Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: How to use the relational operators with IF stetment ?
Replies: 1   Last Post: Mar 24, 2013 12:09 PM

 Messages: [ Previous | Next ]
 James Tursa Posts: 2,326 Registered: 8/5/09
Re: How to use the relational operators with IF stetment ?
Posted: Mar 24, 2013 12:09 PM

"sam " <s_abcdf@yahoo.com> wrote in message <kin7mm\$4a2\$1@newscl01ah.mathworks.com>...
> Hello, I have problem when used the relational operators such as (== , ~= , >=) with the IF statement.
>
> Below the code that explain the problem:
>
> clc;
> RA=[0 1 1 1 ; 1 1 1 0];
> E0=[0 0 0 0];
> e=0;
> RB=0;
>
> if (all(RA(1,:)== E0) && all(RA(2,:) == E0))
> e=e+2;
> elseif ( all(RA(1,:)== E0) && all(RA(2,:) ~= E0))
> PP3=RA(2,:)
> e=e+1;
> elseif ( all(RA(1,:)~= E0) && all(RA(2,:) == E0))
> PP1=RE(1,:)
> e=e+1;
> elseif ( all(RA(1,:)~= E0) && all(RA(2,:) ~= E0))
> e=e+0;
> RB=RA
> end
> --------------
>
> After RUN the results
>
> RB= 0

Here is your relational code rewritten in pseudo code:

if ( 1st Row is all 0's && 2nd Row is all 0's )
e=e+2;
elseif ( 1st Row is all 0's && 2nd Row is all 1's )
PP3=RA(2,:)
e=e+1;
elseif ( 1st Row is all 1's && 2nd Row is all 0's )
PP1=RE(1,:)
e=e+1;
elseif ( 1st Row is all 1's && 2nd Row is all 1's )
e=e+0;
RB=RA
end

Nothing matches, so nothing changes.

James Tursa

Date Subject Author
3/24/13 sam
3/24/13 James Tursa