problem in usong if statement

2 visualizaciones (últimos 30 días)
nevin joseph
nevin joseph el 17 de Jul. de 2012
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 comentario
Jan
Jan el 17 de Jul. de 2012
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.

Iniciar sesión para comentar.

Respuestas (2)

Walter Roberson
Walter Roberson el 17 de Jul. de 2012
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 el 17 de Jul. de 2012
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;

Categorías

Más información sobre Performance and Memory en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by