if statement after use input
43 次查看(过去 30 天)
显示 更早的评论
Is there a possibility of performing an if statement following an user input. For exampl:
Variable = input('type 1,2, or 3 :');
Then stating that if the user typed 1...
I would like to use different values in my equations depending on the value inserted by the user, is this possible?
0 个评论
采纳的回答
Wayne King
2012-2-28
Yes,
Variablein = input('type 1,2,or 3:\n');
if (Variablein == 3)
disp('You typed 3');
end
For a string:
Variablein = input('type 1,2,or 3:\n','s');
Variablein = str2num(Variablein);
if (Variablein == 3)
disp('You typed 3');
end
更多回答(1 个)
Oleg Komarov
2012-2-28
I don't understand probably, but:
Variable = input('type 1,2, or 3 :')
if Variable == 1
...
elseif Variable == 2
...
elseif Variable == 3
...
else
...
end
Or use a switch case statement.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Point Cloud Processing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!