Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.


dpb
Posts:
8,647
Registered:
6/7/07


Re: Displaying messages
Posted:
Mar 6, 2013 2:21 PM


On 3/6/2013 12:21 PM, Achchuthan Ganeshanathan wrote: ...
> ... am writing a function which has an IF function included in > it, I am trying to display messages at each stage. but I seem to be > struggling with it. ... > > > function [ output_args ] = Newfunction( velocity ) ... > if (cond) velocity >= 120;
What's cond? If testing on velocity, then simply
if velocity >= 120; h=msgbox('Your speed is okay'); > else if velocity >=100 & velocity <=100;
'elseif' is a keyword; 'else if' is another else construction Fixing that still leaves a problemvelocity can't ever be both > _and_ < 100 at the same time so the only time that can be satisfied is for the single case of velocity = 100 exactly.
Perhaps the second 100 is a typo for 120 but in that case the <= should be just < to make the two cases nonoverlapping at exactly 120.
> h=msgboc('Warning:Approaching Stall'); > else > h=msgbox('STALL'); > end > end
I'd also suggest looking at the CASE construct for another way to construct such multiple logic...




