Using try/catch in a While Loop to Repeatedly Execute MATLAB Code
(Originally posted on Stuart's MATLAB Videos blog.)
You may be familiar with using
try/catch statements to make your code robust to errors. Matt covered them in a series of posts. A
try/catch statement will catch one occurrence of an error in the try section and then continue to the catch. But what if you want to keep trying the same piece of code until it works? This video shows how to do this by inserting the
try/catch statement in a while loop.
You can skip the section from 6:45 to 9:20, labeled in the table of contents “Breakpoint Not Working” to “Continue Stepping Through tryfunc” where I struggle to understand why something is not working. I eventually explain what is going on @15:45, labeled “Explanation of Breakpoint not working” in the table of contents.
Recorded: 28 Jun 2016
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.