Debugging in MATLAB

In this section, we will learn the basics of debugging and how we can debug in MATLAB.

What is Debugging?

Debugging is the process of stopping the execution of the code at a specific point so that you can analyse the state of the code there to find the mistakes. This is a very important feature of MATLAB that you have to understand and helps you save a lot of time while you have to find the mistake in your code. When the code stops the execution at a specific point, you can look at the values of all the variables there and see if everything's good.

Breakpoints

You can click on the margin left to the line numbers in MATLAB to create a breakpoint. The breakpoint is the point where you code stops executing.

rotate MATLAB

You can see various features in MATLAB for debugging once you are at a break point.

rotate MATLAB

Let's understand how each of these work now.

Continue

Continue, as is name suggests, is used for continuing the execution of the code until the next breakpoint occurs.

Step

Step takes you to the next step of the code.

Step in

Step in takes you into the function in the line that you are executing now.

Step out

Step out bring you out of a function that you may have got into using step in.