Force stop the program if the input doesn't satisfies some conditions
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Fahmy Shandy
am 12 Dez. 2019
Beantwortet: Bhaskar R
am 12 Dez. 2019
Suppose I have a program. And i want to always input the number, that is less or equal than 0,01. I mean, it always .
And if somewhen i made a mistake and input 3 for example, the program will stop and display (Wrong Input!) And display a new row or command line (>>) below it.
What i've tried is :
b=('another input= '); %Not really necessary.
a=input('input any number less than or equal to 0,01= ')
if a>0.01
disp('Wrong Input');
else
a= %some command
end
Sometimes, it works and the program will display that. But it's not always stop, it might be display for "else command" and the program still running.
Or in another case it might be show nothing and the previous command will reappears.
Please help me. Thanks.
0 Kommentare
Akzeptierte Antwort
Bhaskar R
am 12 Dez. 2019
b=('another input= '); %Not really necessary.
while 1
a=input('input any number less than or equal to 0,01= ');
if a<= 0.01
% a= %some command
break;
else
disp('Wrong Input');
end
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!