0% found this document useful (0 votes)
51 views6 pages

Zirwa

The document discusses debugging techniques in MATLAB such as examining variables, setting breakpoints, stopping on errors or warnings, locating errors from messages, using warnings to help debug, and debugging scripts. It also provides examples of calling functions, a factorial function, derivative function, the fprintf function, and times tables for 8 and 23.

Uploaded by

Asma Ch
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views6 pages

Zirwa

The document discusses debugging techniques in MATLAB such as examining variables, setting breakpoints, stopping on errors or warnings, locating errors from messages, using warnings to help debug, and debugging scripts. It also provides examples of calling functions, a factorial function, derivative function, the fprintf function, and times tables for 8 and 23.

Uploaded by

Asma Ch
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

2019-CH-411

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

1. A Quick Way to Examine Variables:

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:

• Break at a specific M-file line number.


• Break at the beginning of a specific sub function.
• Break at the first executable line in an M-file.
• Break when a warning, or error, is generated.
• Break if any infinite or NaN values are encountered.

3. Finding Line Numbers to Set Breakpoints:

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

4. Stopping Execution on an Error or Warning:

If any error to stop program execution then enters debug mode.


5. Locating an Error from the Error Message:
Click on the underlined text in an error message, and MATLAB opens the M-file being executed
in its editor and places the cursor at the point of error.
6. Using Warnings to Help Debug:
You can detect erroneous or unexpected behavior in your programs by inserting warning
messages that MATLAB will display under the conditions you specify. See the section
on Warning Control in the MATLAB "Programming and Data Types" documentation to find out
how to selectively enable warnings.

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:

You might also like