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.

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 27 Feb. 2019

0 Stimmen

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

3 Kommentare

Vahe Ghazikhanian
Vahe Ghazikhanian am 27 Feb. 2019
Unfortunately I am getteing the following error:
Error in test_files (line 66)
bad_files{end+1} = fileName;
Walter Roberson
Walter Roberson am 27 Feb. 2019
I need to see the surrounding code.
In my sample code, FileName should be replaced by the name of the variable that the file name is stored in.
bad_files should be initialized as {}
Vahe Ghazikhanian
Vahe Ghazikhanian am 28 Feb. 2019
Thanks, after I initialized it seems to work.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by