MATLAB: Skip a load error

skip error

Hi,
I want to load some mat files in my folder according to a certain criteria. Sometimes this file doesn't exist. How can I continue to load the next file with causing the program to stop because of the error? example:
UID=unique(ID);
for i=1:size(UID,1) filename=['Data' num2str(UID(i,1))]; load (filename,'DataFinal')
%%% here I want to manipulate the data end
if load returns an error that such a file doesn't exist , how can I continue the loop without any interruption. Regards

Best Answer

You can use a try (catch) block. For example
x = 5;
try
load('asdasdasd.mat') %I can't load this file
catch
disp('Did not load that last file, but it''s ok.');
end
x = x+1;
disp(x)
For more information:
help try