"ernest " <email@example.com> wrote in message news:firstname.lastname@example.org... > "JG" wrote in message <email@example.com>... >> First, according to the current MATLAB documentation of the ?if? >> statement: If expression, statements, end >> >> The statements are executed if the evaluation of expression yields a >> logical 1 or a nonzero result. >> >> Now, I?ve inherited some code which implies that, at one time in MATLAB >> history, the statements were executed if the evaluation of the expression >> yields a logical 1 or a nonzero, positive result. That is, the ?if? >> statement would fail if the expression returned a negative result. >> >> Does anyone remember such a time? If so, do you remember when it >> changed? I believe this code was written around 2005. >> >> >> thanks- JG > > Good question. As I recall from other computers/languages a logical FALSE > was defined as zero (0) and anything else was TRUE. Specifically for > MATLAB in the Student Edition of Version 5 on page 63, "The isequal > function returns logical True (1) when two arrays have the same dimensions > and identical elements. Otherwise, it returns logical False (0)". However, > in the same work, page 117 in section 11.3 if-else-end Constructions, it > states, " > if expression > commands... > end > The commands... between the if and end statements are evaluated if all > elements in expression are TRUE (nonzero).
Yes, that's what Bruno said.
> The book was published in 1997. > > The 1997 definition of TRUE appears to agree with JG's definition.
? It doesn't mention positivity at all and so would seem to REFUTE the implication of that code.
I just ran MATLAB 5.0 (from 1996) and executed this code:
if -1 disp('Negative is true') else disp('Negative is false') end
The result I received:
Negative is true
The HELP for IF also includes this statement:
The statements are executed if the real part of the expression has all non-zero elements. The ELSE and ELSEIF parts are optional.
So if there was a version of MATLAB for which IF considered negative numbers to be false, it would probably have to be prior to MATLAB 5. I am almost certain this behavior has not changed since MATLAB 5.
JG, is it possible that the person who wrote the code that made that implication was simply being overcautious? Can you show a small sample of the code that makes that implication?