Code Comments
Programming Forum and web based access to our favorite programming groups.Hi, I have a logical NxM array. How do I find indeces of elements which are equal to 1?
Post Follow-up to this messagethe reason I want to do this is because I have a logical statement which returns NxM logical matrix B flagging the values from another numeric matrix A which I need to do operations on. I want to update values of A at indeces found from B with new values. I know that A(B), where B is numeric, will do the job. That's why I want to find indeces of 1's in my logical B array.
Post Follow-up to this messageOn Tue, 31 May 2005 13:44:14 -0700, bobrics wrote: > the reason I want to do this is because I have a logical statement > which returns NxM logical matrix B flagging the values from another > numeric matrix A which I need to do operations on. > > I want to update values of A at indeces found from B with new values. > > I know that A(B), where B is numeric, will do the job. That's why I > want to find indeces of 1's in my logical B array. Why don't you just use the logical matrix directly? You can. If you really want the numeric indices, type help find Dan
Post Follow-up to this messagebobrics wrote: > > > the reason I want to do this is because I have a logical statement > which returns NxM logical matrix B flagging the values from > another > numeric matrix A which I need to do operations on. > > I want to update values of A at indeces found from B with new > values. > > I know that A(B), where B is numeric, will do the job. That's why I > want to find indeces of 1's in my logical B array. > > One among many. Probably fast. Surely a bit cryptic. Does it help you? B = 1 0 1 0 0 1 0 1 0 A = 117 1 117 3 5 117 4 117 2 / per
Post Follow-up to this messageThat helped a lot.. I was doing that before.. but I guess made some mistake... instead of putting the values at indeces, it just replaced the whole matrix,,, even though I was using logical vector. The end result is more important! Thank you guys!
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.