Stuart’s MATLAB Videos

Watch and Learn

Using try/catch in a While Loop to Repeatedly Execute MATLAB Code

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.

Play the video in full screen mode for a better viewing experience.

|
  • print

댓글

댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.