Download presentation
Presentation is loading. Please wait.
Published byLynn Richard Modified over 8 years ago
1
Debugging M-Files Steve Gu Feb 08, 2008
2
Outline What’s Debugging? Types of Errors Finding Errors Debugging Example Using Debugging Features
3
What’s Debugging? Debugging is the process by which you can – Recognize a bug exists – Isolate source of bug – Identify cause of bug – Determine fix for bug
4
Types of Errors Syntax Errors – Misspelling – Omitting parenthesis – MATLAB detects most syntax error and display error message in the command window Run-time Errors – Modify the wrong variables – Perform a calculation incorrectly – Apparent when an M-file produces unexpected result
5
Find Errors For syntax errors – Easy – MATLAB’s error messages For Run-time errors – More difficult – Some useful techniques: Remove ; Add keyboard statements K>> type return Run M-file as a script Use the ‘depfun’: e.g,list = depfun('binomial','-toponly'); Use the MATLAB Editor/Debugger or debugging functions
6
Debugging Example –Binomial.m
7
Using Debugging Features Preparing for Debugging Setting Breakpoints Running an M-File with Breakpoints Stepping through an M-File Examining Values Correcting Problems and Ending Debugging
8
Preparing for Debugging Open the file – To use the Editor/Debugger Save changes
9
Setting Breakpoint Setting Breakpoints Using the Editor – Set/Clear Breakpoint Function Equivalent – dbstop in binomial at 14 – Some Useful related functions dbtype :Lists the M-file code dbstatus :Lists breakpoints
10
Running an M-File with Breakpoints Run M-file from command window or Editor K>> -------MATLAB is in debug mode The program is paused at the first breakpoint The function displayed in the Stack changes to reflect the current function
11
Stepping Through an M-File
12
Examining Values Viewing Datatips in the Editor/Debugger Viewing Values in the Array Editor
13
Viewing Values in Array Editor
14
Ending Debugging Quit Debugging Clear all the breakpoints in the file Make changes to the M-file Save M-file
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.