problem in usong if statement
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Jan
le 17 Juil 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.
Réponses (2)
Walter Roberson
le 17 Juil 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
0 commentaires
Kevin Claytor
le 17 Juil 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;
0 commentaires
Voir également
Catégories
En savoir plus sur Performance and Memory dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!