problem in usong if statement

조회 수: 4 (최근 30일)
nevin joseph
nevin joseph 2012년 7월 17일
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
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
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

Kevin Claytor
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;

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by