how to display a error message then proced further when the string doesnot matches by using for and if loop

2 Ansichten (letzte 30 Tage)
this is my program
list={'AOA','CAS','IAS','ALT'};
prompt='Enter variable name';
a=input(prompt,'s');
b=strcmp(a,list);
if input does not matches with the list of variables then it must show an error 'Variable not found, please try again' (for three times) & if the user enters invalid variable for three times the program should be terminated.

Antworten (3)

Chandrasekhar
Chandrasekhar am 7 Mär. 2014
try
....your code
catch exception
disp(exception.message)
end

Ravikant Singh
Ravikant Singh am 7 Mär. 2014
Its not working

Walter Roberson
Walter Roberson am 7 Mär. 2014
trycount = 0;
while trycount < 3
....
if no match
trycount = trycount + 1
end
end
if trycount >= 3
user blew it
end
  1 Kommentar
Ravikant Singh
Ravikant Singh am 7 Mär. 2014
just have a look on my program once again the last statement will store 1 or 0 in variable now i want to display an error when m=0 so how to do ??

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Get Started with MATLAB 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!

Translated by