What does this command mean?

34 Views Asked by At

I am unable to interpret the following command in a MATLAB code

while (fa > 0) == (fb > 0)

I thought it says: if fa>0 , fb > 0 and both are equal to each other then do some commands.

However, while running in debug mode, at I found that even then fa and fb were < 0 and not equal to each other, the commands were still executed. May someone kindly help in correct interpretation of the command

This is the beginning of a while loop

Thanks

2

There are 2 best solutions below

0
On BEST ANSWER

fa > 0 returns a true/false vector for each entry, which is true iff the entry is positive.

Therefore, (fa > 0) == (fb > 0) is true iff all corresponding entries of fa and fb ahve the same signs.

In other words, $fa = [1,-1]$ and $fb = [-1,1]$ would cause it to be false, but $fa = [-1,-1]$ and $fb = [-2,-3]$ would make it true.

3
On

fa>0 is a boolean value, meaning it evaluates to either true or false.
The same is true for fb>0
So this is stating that if both fa>0 and fb>0 evaluate to true, then do the stuff in the loop.
Likewise if both fa>0 and fb>0 evaluate to false, then you still do the stuff in the loop.
This is because true=true and false=false