Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Check for row by [r,c]...help

Subject: Check for row by [r,c]...help

From: alfann

Date: 13 Jun, 2010 17:57:42

Message: 1 of 3

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

Subject: Check for row by [r,c]...help

From: us

Date: 13 Jun, 2010 18:15:05

Message: 2 of 3

alfann <alfann.net@hotmail.com> wrote in message <1657129308.327684.1276452008402.JavaMail.root@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

Subject: Check for row by [r,c]...help

From: Jos (10584)

Date: 13 Jun, 2010 21:10:04

Message: 3 of 3

alfann <alfann.net@hotmail.com> wrote in message <1657129308.327684.1276452008402.JavaMail.root@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

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us