MATLAB provides common debugging tools such as breakpoints for use in scripts and functions.
- [Instructor] MATLAB also provides us some standard debugging tools that we can use if we ever have issues with our scripts or our functions. Let's go ahead and open up the LetsLoop script. And if you recall, in this script, we set a threshold value of eight. And then we instantiated a while loop where we generate a random number between nine and ten, check if its greater than the threshold, and if it is, we display shut down, break out of our loop. And if not, we display, everything is okay.
So right here next to the line numbers, in the script editor, we see these little dashes and that's where we set breakpoints. So let's click on the breakpoint indicator here on line six and that will stop us right after our random number is generated and before we test it. I'm going to go ahead and drag the command window up here to give myself some more real estate and let's hit run. So we can see now that we're in debug mode with this K here right next to the command line interface. And we can also see the green arrow next to line six here indicating our debugger has paused.
So now that our script is paused, we can do things like check the value of num. We can see that it's equal to nine so we can anticipate that our threshold has been met and our while loop will quit. Let's hit continue running from breakpoint and see if that happens. There we go, we were over the limit, so we shut down. We can see now that the K is gone and we're out of debug mode. Let's run it one more time and see if we can get under the limit. It stopped again. What's our number this time? Our number is ten, so we'll need to shut down one more time.
Let's go ahead and run it one more time just for fun. Now let's see what our number is. All right, our number is two. So if we hit continue, we should stay in the loop and hit our breakpoint one more time. Sure enough, everything is okay. We test our number one more time. It's ten so we can again anticipate that our brute loop is going to shut down. Some pretty simple functionality but it allows us to debug our scripts and functions just like we would in many other IDEs.
- Creating MATLAB variables
- Working with matrix and scalar operations
- Using if statements and loops
- Creating functions
- Importing data
- Building basic plots and 3D plots
- Working with images
- Creating Simulink models