if and elseif statement with unexpected error that I cannot figure out
Afficher commentaires plus anciens
I am trying to a) Create a script with if & elseif statements that will output one of three statements given three potential conditions:
1) If X & Y are < 3 but > 0: output the statement ‘X and Y are Less than 3 but greater than 0’.
2) If X and Y are less than 0: output the statement ‘X and Y are negative’
3) If X or Y are > 3: output ‘Either X or Y is greater than 3’. And lastly if none of the above conditions are met, output ‘None of the three conditions have been met’.
Where x=-0.5, y=-2
my script:
>> x=-0.5,y=-2
if x < 3 && y < 3 && x >0 && x>0
disp (‘X and Y are Less than 3 but greater than 0’)
elseif X<0 && Y<0
disp (‘X and Y are negative’)
elseif X>3 || Y>3
disp (‘Either X or Y is greater than 3’)
else
disp (‘None of the three conditions have been met’)
end
x =
-0.5000
y =
-2
My display is wrong:
disp (‘X and Y are Less than 3 but greater than 0’)
|
Here is my error:
Error: The input character is not valid in MATLAB statements
or expressions.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!