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: History of the MATLAB "if" statement
Replies: 1   Last Post: Jan 7, 2013 4:48 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
Steven Lord

Posts: 17,944
Registered: 12/7/04
Re: History of the MATLAB "if" statement
Posted: Jan 7, 2013 4:48 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply



"ernest " <ernest.barczak@l-3com.com> wrote in message
news:kcfbnl$iu$1@newscl01ah.mathworks.com...
> "JG" wrote in message <kcf8b8$g22$1@newscl01ah.mathworks.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?

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com




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.