"John Smith" <johnps@gmail.com> wrote in message <j20h6a$dgg$1@newscl01ah.mathworks.com>...
> When I use &, I get the following message:
>
> "Use && instead of & as the AND operator in (scalar) conditional statements."
>
> I wanted to compare two vectors element by element, as well write a conditional statement for just one of the elements of one of the vectors (i.e., solution1(13)>=0 & solution1~=solution2). If I use &&, I can't compare the two vectors as a whole, i.e., element by element. On a simple test I performed, it seemed that & worked fined for writing a conditional statement for just one of the elements.
>
> I hope I'm making sense. My question is, what's wrong with only using &, and never using &&?
&& is use with boolean scalar expression all skip an evaluation together when it's not needed.
Example, the statement:
b = ~isempty(a) && a(1) > 2;
works for a = [] and as well a = [1 2];
If && is replaced by &, Matlab throws error if a = [];
Bruno
