MATLAB Programming
MATLAB Programming MATLAB Programming
12 Programming Tips Debugging This section covers the following topics: • “The MATLAB Debug Functions” on page 12-22 • “More Debug Functions” on page 12-22 • “The MATLAB Graphical Debugger” on page 12-23 • “A Quick Way to Examine Variables” on page 12-23 • “Setting Breakpoints from the Command Line” on page 12-24 • “Finding Line Numbers to Set Breakpoints” on page 12-24 • “Stopping Execution on an Error or Warning” on page 12-24 • “Locating an Error from the Error Message” on page 12-24 • “Using Warnings to Help Debug” on page 12-25 • “Making Code Execution Visible” on page 12-25 • “Debugging Scripts” on page 12-25 The MATLAB Debug Functions For a brief description of the main debug functions in MATLAB, type help debug For more information: See Debugging M-Files in the MATLAB Desktop Tools and Development Environment documentation. More Debug Functions Other functions you may find useful in debugging are listed below. Function echo disp sprintf, fprintf Description Display function or script code as it executes. Display specified values or messages. Display formatted data of different types. 12-22
Debugging Function whos size keyboard return warning error lasterr lasterror lastwarn Description List variables in the workspace. Show array dimensions. Interrupt program execution and allow input from keyboard. Resume execution following a keyboard interruption. Display specified warning message. Display specified error message. Return error message that was last issued. Return last error message and related information. Return warning message that was last issued. The MATLAB Graphical Debugger Learn to use the MATLAB graphical debugger. You can view the function and its calling functions as you debug, set and clear breakpoints, single-step through the program, step into or over called functions, control visibility into all workspaces, and find and replace strings in your files. Start out by opening the file you want to debug using File > Open or the open function. Use the debugging functions available on the toolbar and pull-down menus to set breakpoints, run or step through the program, and examine variables. For more information: See Debugging M-Files and Using Debugging Features in the MATLAB Desktop Tools and Development Environment documentation. AQuickWaytoExamineVariables To see the value of a variable from the Editor/Debugger window, hold the mousecursoroverthevariablenameforasecondortwo. Youwillseethe value of the selected variable displayed. 12-23
- Page 756 and 757: 10 Scheduling Program Execution wit
- Page 758 and 759: 10 Scheduling Program Execution wit
- Page 760 and 761: 10 Scheduling Program Execution wit
- Page 762 and 763: 11 Improving Performance and Memory
- Page 764 and 765: 11 Improving Performance and Memory
- Page 766 and 767: 11 Improving Performance and Memory
- Page 768 and 769: 11 Improving Performance and Memory
- Page 770 and 771: 11 Improving Performance and Memory
- Page 772 and 773: 11 Improving Performance and Memory
- Page 774 and 775: 11 Improving Performance and Memory
- Page 776 and 777: 11 Improving Performance and Memory
- Page 778 and 779: 11 Improving Performance and Memory
- Page 780 and 781: 11 Improving Performance and Memory
- Page 782 and 783: 11 Improving Performance and Memory
- Page 784 and 785: 11 Improving Performance and Memory
- Page 786 and 787: 12 Programming Tips MATLAB Path (p.
- Page 788 and 789: 12 Programming Tips numberOfLines)
- Page 790 and 791: 12 Programming Tips Help This secti
- Page 792 and 793: 12 Programming Tips Topic Name arit
- Page 794 and 795: 12 Programming Tips Youcangethelpon
- Page 796 and 797: 12 Programming Tips Commenting Out
- Page 798 and 799: 12 Programming Tips For M-file func
- Page 800 and 801: 12 Programming Tips Function Argume
- Page 802 and 803: 12 Programming Tips Passing Argumen
- Page 804 and 805: 12 Programming Tips For more inform
- Page 808 and 809: 12 Programming Tips Setting Breakpo
- Page 810 and 811: 12 Programming Tips Variables This
- Page 812 and 813: 12 Programming Tips AvoidUsingiandj
- Page 814 and 815: 12 Programming Tips Strings This se
- Page 816 and 817: 12 Programming Tips Function regexp
- Page 818 and 819: 12 Programming Tips are useful when
- Page 820 and 821: 12 Programming Tips File Precedence
- Page 822 and 823: 12 Programming Tips Making Nontoolb
- Page 824 and 825: 12 Programming Tips Using switch Ve
- Page 826 and 827: 12 Programming Tips try X = A * B c
- Page 828 and 829: 12 Programming Tips • Load spread
- Page 830 and 831: 12 Programming Tips Files and Filen
- Page 832 and 833: 12 Programming Tips -- METHOD #1 --
- Page 834 and 835: 12 Programming Tips Readable File F
- Page 836 and 837: 12 Programming Tips Starting MATLAB
- Page 838 and 839: 12 Programming Tips Finding the MAT
- Page 840 and 841: 12 Programming Tips For More Inform
- Page 842 and 843: A External Interfaces A-2
- Page 844 and 845: Index arithmetic operators 3-17 ove
- Page 846 and 847: Index debugging 9-6 designing 9-9 j
- Page 848 and 849: Index string, vector of input 2-70
- Page 850 and 851: Index internet 6-116 downloading fr
- Page 852 and 853: Index overloaded 5-37 function work
- Page 854 and 855: Index I if and empty arrays 3-89 ex
Debugging<br />
Function<br />
whos<br />
size<br />
keyboard<br />
return<br />
warning<br />
error<br />
lasterr<br />
lasterror<br />
lastwarn<br />
Description<br />
List variables in the workspace.<br />
Show array dimensions.<br />
Interrupt program execution and allow input from<br />
keyboard.<br />
Resume execution following a keyboard<br />
interruption.<br />
Display specified warning message.<br />
Display specified error message.<br />
Return error message that was last issued.<br />
Return last error message and related information.<br />
Return warning message that was last issued.<br />
The <strong>MATLAB</strong> Graphical Debugger<br />
Learn to use the <strong>MATLAB</strong> graphical debugger. You can view the function<br />
and its calling functions as you debug, set and clear breakpoints, single-step<br />
through the program, step into or over called functions, control visibility into<br />
all workspaces, and find and replace strings in your files.<br />
Start out by opening the file you want to debug using File > Open or the<br />
open function. Use the debugging functions available on the toolbar and<br />
pull-down menus to set breakpoints, run or step through the program, and<br />
examine variables.<br />
For more information: See Debugging M-Files and Using Debugging<br />
Features in the <strong>MATLAB</strong> Desktop Tools and Development Environment<br />
documentation.<br />
AQuickWaytoExamineVariables<br />
To see the value of a variable from the Editor/Debugger window, hold the<br />
mousecursoroverthevariablenameforasecondortwo. Youwillseethe<br />
value of the selected variable displayed.<br />
12-23