From: Roger Stafford on
"Brendan " <c_uboid88(a)hotmail.co.uk> wrote in message <hpib30$9s4$1(a)fred.mathworks.com>...
> Hi,
> I have a 1110x4 array and want to find the row in which a certain condition is satisfied..
> For example if I have:
> Y=[y1;y2;y3;y4] where y1,y2,y3,y4 are 1110 long vectors,
> I want to find the row in which:
> atan2(y1/y2)==certain value.
>
> I can find the row for Max and Min using [C,I]=min(Y) etc but am not sure how to check if the atan2 condition is satisfied.
> Any ideas? Im sure its relatively easy but...
> Thanks
> Brendan

"Find" is the right word to use. With your atan2 example you could use:

row = find(atan2(Y(:,1),Y(:,2))==value);

However, since atan2 values are subject to round off errors, this would probably not be what you want. It is too restrictive. You should rather have something like this:

row = find(abs(atan2(Y(:,1),Y(:,2))-value)<tol);

where 'tol' is some suitably small value that would safely allow for all such rounding errors.

Roger Stafford
From: Matt Fig on
find(atan2(Y(:,2),Y(:,1))==somevalue)

Note that you are likely to encounter floating point problems with such an equality comparison. You might want to do:

find(abs(atan2(Y(:,2),Y(:,1))-somevalue)<tol) % For some tolerance.
From: Brendan on
"Matt Fig" <spamanon(a)yahoo.com> wrote in message <hpie5o$q7g$1(a)fred.mathworks.com>...
> find(atan2(Y(:,2),Y(:,1))==somevalue)
>
> Note that you are likely to encounter floating point problems with such an equality comparison. You might want to do:
>
> find(abs(atan2(Y(:,2),Y(:,1))-somevalue)<tol) % For some tolerance.

Thanks guys, Ive come across the floating error thing before so I definitely will have to use the tolerance, but thanks a million for the posts!
Brendan