How do I in MatLab catch the error that occours when the user enters letters and other things that aren't numbers in the input:
width = input('Enter a width: ');
I have played around for a while with the try/catch command:
width = 0;
message = '';
% Prompting.
while strcmp(message,'Invalid.') || width < 1 || width ~= int32(width)
try
disp(message)
width = input('Frame width: ');
catch error
message = 'Invalid.';
end
end
But with no luck (the above doesn't work). As shown I would like a simple message like "Frame width: " for the user the first time he has to enter his choice. But if an error is caught I want the message for him to be "Invalid. Try again: " fx everytime an error occours.
I have also tried the error() but I don't know how to place that correctly. Since the error() doesn't take the input command, where the error happends, as an argument, it must detect it in another way, which I can't figure.
Any help would be appreciated.