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

1 次查看(过去 30 天)
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.

回答(3 个)

Chandrasekhar
Chandrasekhar 2014-3-7
try
....your code
catch exception
disp(exception.message)
end

Ravikant Singh
Ravikant Singh 2014-3-7
Its not working

Walter Roberson
Walter Roberson 2014-3-7
trycount = 0;
while trycount < 3
....
if no match
trycount = trycount + 1
end
end
if trycount >= 3
user blew it
end

类别

Help CenterFile Exchange 中查找有关 Downloads 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by