From: neo sam on
Hello all,
I am working on Matlab and need some help. How can I search for a single element from a nx2 matrix? for example:

if A = 12 0
15 1
17 0
19 0
20 1
then how can I find out whether the value of '20' is '1' or '0' ?
I'm just using this as a flag and cant seem to figure it out. Is there any other way of doing this?

Thank you.
From: dpb on
neo sam wrote:
> Hello all,
> I am working on Matlab and need some help. How can I search for a single
> element from a nx2 matrix? for example:
>
> if A = 12 0
> 15 1
> 17 0
> 19 0
> 20 1
> then how can I find out whether the value of '20' is '1' or '0' ?
> I'm just using this as a flag and cant seem to figure it out. Is there
> any other way of doing this?

doc find

read section on logical indexing

Depending on what you're next wanting to do, options vary...

A few options, there are many perturbations and others will undoubtedly
add many...hopefully this will get you started anyway...

>> if A(A(:,1)==20,2)==1, disp('found'), end
found
>> idx=find(A(:,1)==20)
idx =
5
>> A(idx,2)==1
ans =
1
>>
From: neo sam on
dpb <none(a)non.net> wrote in message <i0tslb$798$1(a)news.eternal-september.org>...
> neo sam wrote:
> > Hello all,
> > I am working on Matlab and need some help. How can I search for a single
> > element from a nx2 matrix? for example:
> >
> > if A = 12 0
> > 15 1
> > 17 0
> > 19 0
> > 20 1
> > then how can I find out whether the value of '20' is '1' or '0' ?
> > I'm just using this as a flag and cant seem to figure it out. Is there
> > any other way of doing this?
>
> doc find
>
> read section on logical indexing
>
> Depending on what you're next wanting to do, options vary...
>
> A few options, there are many perturbations and others will undoubtedly
> add many...hopefully this will get you started anyway...
>
> >> if A(A(:,1)==20,2)==1, disp('found'), end
> found
> >> idx=find(A(:,1)==20)
> idx =
> 5
> >> A(idx,2)==1
> ans =
> 1
> >>


This does the trick! thank you so much!