I'm converting some .dat files into .mat files using a function. I'm calling this function inside a loop to convert a number of files. There are some cases where my .dat file is corrupted and the function cannot convert and an error occurs, stopping the loop.
Now my question is: Is there any command wherein when the error occurs it should skip the current (i) value in the loop and go for the next increment value (in my case the next file)?
You can do this using a TRY/CATCH statement along with CONTINUE. Place the following inside your loop:
EDIT:
Amro suggests a good idea in his comment below. You may want to issue a warning showing that the error occurred and for which file, or perhaps you may even want to save a list of the files that failed to convert properly. To do the latter, you can first initialize an empty cell array before you start your loop:
Then, after you catch the exception but before you issue the
continue
command, add the name/path of the current file being converted to the list:When your loop is done, you can then look at
failedFiles
to easily see what didn't convert properly.