Clear Filters
Clear Filters

if statement in Matlab

4 views (last 30 days)
Sergey Dukman
Sergey Dukman on 16 May 2015
Commented: Star Strider on 16 May 2015
I running the following if-loop:
sigmat=24;
n=1.5;
sigmam=20;
N=200;
si=sigmat/n;
if si>=sigmam
F=N/si;
end;
But after this script is run out I can not claim a value of F in command window (F should be equal 12,5). Where did I mistake in this script?

Accepted Answer

Star Strider
Star Strider on 16 May 2015
Edited: Star Strider on 16 May 2015
The problem is that ‘si’ is 16 and ‘sigmam’ is 20. The if condition always evaluates to false, and the if block never executes.
Also, if you want ‘F’ to output to the Command Window, remove the semicolon at the end of the line. The presence of the semicolon suppresses Command Window output:
F=N/si
----------
I like your avatar!
  3 Comments
Sergey Dukman
Sergey Dukman on 16 May 2015
Sorry!
I got it now. I have to use opposite condition as si<=sigmam to define F.
thank you Sir!
Yours look also good :)
Star Strider
Star Strider on 16 May 2015
My pleasure!
Save the Polar Bears!

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!