MATLAB: How to handle load errors.

error handlingtry statement

I have a large number of files to read and proces. A small percentage of these files are corrupted. I use the load() command to load individual files in a parfor loop statement. Unfortunately my program stops ececution when one of these corrupt files gives an error when loading.
How could I continue execution? Buy this I mean advancing the loop variable and not processing the data from faulty file?
I also need to record the name of the file that triggered the error.

Best Answer

try
filestruct = load(FileName);
catch ME
bad_files{end+1} = FileName;
continue; %skip computing with this file
end