Zirwa
Zirwa
Zirwa Noor
Lab Report # 04
Debugging and Call function
What is Debugging?
Diagnose problems, check syntax and release compatibility. As you work in the Editor and
Live Editor, MATLAB automatically identifies potential coding problems. Debugging features
help you diagnose specific issues.
Debugging Process:
1. A Quick Way to Examine Variables
2. Setting Breakpoints from the Command Line
3. Finding Line Numbers to Set Breakpoints
4. Stopping Execution on an Error or Warning
5. Locating an Error from the Error Message
6. Using Warnings to Help Debug
7. Debugging Script
To see the value of a variable from the Editor/Debugger window, hold the mouse cursor over the
variable name for a second or two. You will see the value of the selected variable displayed.
2. Setting Breakpoints from the Command Line:
When debugging from the command line, a quick way to find line numbers for setting
breakpoints is to use dbtype. The dbtype function displays all or part of an M-file, also
numbering each line. To display copyfile.m, use
❖ dbtype copyfile.m
7. Debugging Scripts:
Scripts store their variables in a workspace that is shared with the caller of the script. So, when
you debug a script from the command line, the script uses variables from the base workspace. To
avoid errors caused by workspace sharing, type clear all before starting to debug your script to
clear the base workspace.
Call Function:
❖ You can add them to a MATLAB class. Then instantiate an object of this class and call
any of the functions.
❖ It should be something like this:
❖ In a separate file (ex, functionsContainer.m)
❖ Then, in your script create an object:
❖ Finally, call whatever function you like.
Factorial Function:
Derivative Function:
“fprintf” Function:
The function fprintf () is known as format print function. It writes and formats the output to a
stream. It is used to print the message but not on stdout console.
Times Table :
For 8:
For 23: