Debugging M-FilesSteve GuFeb 08, 2008Outline• What’s Debugging?• Types of Errors• Finding Errors• Debugging Example• Using Debugging FeaturesWhat’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 bugTypes 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 resultFind 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 functionsDebugging Example –Binomial.mUsing Debugging Features• Preparing for Debugging• Setting Breakpoints• Running an M-File with Breakpoints• Stepping through an M-File• Examining Values• Correcting Problems and Ending DebuggingPreparing for Debugging• Open the file – To use the Editor/Debugger• Save changesSetting 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 breakpointsRunning 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 functionStepping Through an M-FileExamining Values• Viewing Datatips in the Editor/Debugger• Viewing Values in the Array EditorViewing Values in Array EditorEnding Debugging• Quit Debugging• Clear all the breakpoints in the file• Make changes to the M-file• Save
View Full Document