Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
James Tursa

Posts: 2,096
Registered: 8/5/09
Re: How to use the relational operators with IF stetment ?
Posted: Mar 24, 2013 12:09 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.