From: alfann on
Hi,
If I have this code:
[r, c] = find(ax == val);
and the output (for example) is equal to:
r =

1
2
3
2
2

c =

2
2
2
3
4

I want to do if statement which is :
If any value from (r) is equal to 1
abc=11
else
abc=22
end

how can I create this condition?please
From: us on
alfann <alfann.net(a)hotmail.com> wrote in message <1657129308.327684.1276452008402.JavaMail.root(a)gallium.mathforum.org>...
> Hi,
> If I have this code:
> [r, c] = find(ax == val);
> and the output (for example) is equal to:
> r =
>
> 1
> 2
> 3
> 2
> 2
>
> c =
>
> 2
> 2
> 2
> 3
> 4
>
> I want to do if statement which is :
> If any value from (r) is equal to 1
> abc=11
> else
> abc=22
> end
>
> how can I create this condition?please

well... you're almost there

if any(r==1)
disp('has');
else
disp('has not');
end

us
From: Jos (10584) on
alfann <alfann.net(a)hotmail.com> wrote in message <1657129308.327684.1276452008402.JavaMail.root(a)gallium.mathforum.org>...
> Hi,
> If I have this code:
> [r, c] = find(ax == val);
> and the output (for example) is equal to:
> r =
>
> 1
> 2
> 3
> 2
> 2
>
> c =
>
> 2
> 2
> 2
> 3
> 4
>
> I want to do if statement which is :
> If any value from (r) is equal to 1
> abc=11
> else
> abc=22
> end
>
> how can I create this condition?please

Urs gave you the solution to your problem.

You should, however, think about what it means if the variable r contains a 1. It means



....




that the first row of ax contains the value you're looking for. So, why bother with the other rows, and why use FIND at all?

q = any(ax(1,:)==val)
if q, abc = ...

hth
Jos
 | 
Pages: 1
Prev: Real time Analysis
Next: interactive video player