0% found this document useful (0 votes)
7 views9 pages

Matlab Debugging Techniques Explained

Computer Aided Design (CAD) involves debugging programs using Matlab. There are three types of errors: 1) Syntax errors found by Matlab before execution, 2) Runtime errors found during execution, and 3) Logical errors where the program runs but produces wrong answers. Matlab allows setting breakpoints to step through code line-by-line to locate bugs. Key debugging tools include stepping into or out of functions and tracking variable values at each step to pinpoint logical errors.

Uploaded by

Clady
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)
7 views9 pages

Matlab Debugging Techniques Explained

Computer Aided Design (CAD) involves debugging programs using Matlab. There are three types of errors: 1) Syntax errors found by Matlab before execution, 2) Runtime errors found during execution, and 3) Logical errors where the program runs but produces wrong answers. Matlab allows setting breakpoints to step through code line-by-line to locate bugs. Key debugging tools include stepping into or out of functions and tracking variable values at each step to pinpoint logical errors.

Uploaded by

Clady
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

Computer Aided Design (CAD)

 Matlab Debugging

Dr. Sawsan Abdellatif 1


Reference:

Matlab by Example: Programming Basics, Munther Gdeisat

2
3
 Bugs: Errors in programs.
 Debugging: the process of locating and eliminating bugs

1- Syntax Error 2- Runtime Error


 Ex. misspelling of variable or  Runtime errors are found by Matlab
function names or missing quotes or during the execution of a program
parentheses..
 Matlab checks syntax first before Example:
executing commands.
 Matlab give some information helps
in identifying and fixing this error.
Examples:

4
3- Logical Error

 Logical errors occur when the program compiles and runs


successfully but produces the wrong answer.

 Example: if we need Matlab program to calculate the absolute values of a vector


(Ex. Values from -10 to 10)

 Note: the result is not as required. So we need to fix this bug using Matlab’s
debugging capabilities to track down the location and exact nature of the bug.

5
Break point

Set break point as shown then “Run” the code. The


Command Prompt changes to:
This means debug mode

Matlab starts executing the program and stops at line 1.

6
To direct Matlab to run the command in line 1, click on the Step icon. Matlab runs the
first line and then proceeds to line 2.

7
After determining the error and fix it. Then step through the program

First step indicate correct operation

First 3 steps indicate correct operation 8


Step In Tool: Track bugs inside functions

Step Out Tool: To run the function all together in a single step. This
executes the rest of the commands in the function and returns the
control to the file from which we call the function.

You might also like