For Programmers: Free Programming Magazines  


Home > Archive > Matlab > May 2005 > Find indeces of 1's in logical array









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Find indeces of 1's in logical array
bobrics

2005-05-31, 9:01 pm

Hi,
I have a logical NxM array. How do I find indeces of elements which are
equal to 1?

bobrics

2005-05-31, 9:01 pm

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.

Dan Hensley

2005-05-31, 9:01 pm

On 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
per isakson

2005-05-31, 9:01 pm

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.
>
>


One among many. Probably fast. Surely a bit cryptic. Does it help
you?
[color=darkred]
B =
1 0 1
0 0 1
0 1 0[color=darkred]
A =
117 1 117
3 5 117
4 117 2[color=darkred]

/ per
bobrics

2005-05-31, 9:01 pm

That 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!

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com