problem in usong if statement
2 次查看(过去 30 天)
显示 更早的评论
if( V2>V1 && V1>V3)
{
if(I2>I3)
disp('RANGE IS 60-90');
if(I3>I2)
disp('RANGE IS 240-270');
}
am getting an error of using if inside another if....how can i resolve this problem
1 个评论
Jan
2012-7-17
The usage of the IF statement is explained in the documentation exhaustively. Please take the time to read "help if" and "doc if". It is strongly recommended to read the "Getting Started" chapters also to learn the absolute basics.
回答(2 个)
Walter Roberson
2012-7-17
That is not valid MATLAB code. MATLAB does not use "{" or "}", and each "if" must be matched with an "end" statement.
Sample:
if condition1
if condition2
do something
end
end
0 个评论
Kevin Claytor
2012-7-17
You cannot use the brackets {} to group, and use the keyword 'end' to close if and for statements. If you absolutely must have it on one line, this should work;
if( V2>V1 && V1>V3); if(I2>I3); disp('RANGE IS 60-90'); elseif(I3>I2) disp('RANGE IS 240-270'); end; end;
Otherwise, I find using new lines and proper indentation (you can auto indent with ctrl-i) makes things much clearer;
if( V2>V1 && V1>V3)
if(I2>I3)
disp('RANGE IS 60-90');
elseif(I3>I2)
disp('RANGE IS 240-270');
end;
end;
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Performance and Memory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!