From: someone on
"Tim " <thurst(a)remove.this.iastate.edu> wrote in message <hb2mv8$488$1(a)fred.mathworks.com>...
> Hello,
> I'm trying to catch load a file with code but if the file does not exist, I want the user to be able to try again with a different filename.
>
> % START
> instrument = input('Enter instrument number (3 or 4): ', 's');
> myrun = input('Enter Request ID (5 digit number): ', 's');
> myfile = ['Z:\Instrument2.0.' instrument '\' myrun '.mat'];
>
> try
> load(myfile);
> catch
> error('Incorrect instrument or Request ID. %s not found', myfile)
> end
>
>
> I would like the code to loop back up to the START when an error occurs when attempting to load 'myfile'. I have tried to do some different loops but none have worked. Please help.

% Have you tried sometning like:

% START
instrument = input('Enter instrument number (3 or 4): ', 's');
myrun = input('Enter Request ID (5 digit number): ', 's');
myfile = ['Z:\Instrument2.0.' instrument '\' myrun '.mat'];
test = 1;
while test
try
load(myfile);
test = 0;
catch
error('Incorrect instrument or Request ID. %s not found', myfile)
myfile = input('prompt', 's')
test = 1;
end
end

% Caution: The above code is untested.
% You may also look into usung exit instead of the try/catch, i.e.

A = exist('name','file')

% A = 2 when name is the full pathname to a file or
% the name of an ordinary file on your MATLAB search path.