Download presentation

Presentation is loading. Please wait.

Published byJaelyn Peacock Modified over 3 years ago

1
Debugging in Matlab C. Reed 4/5/11

2
Bugs Debugging is a natural part of programming: Three standard types of errors: –Syntax errors: you simply have typed an illegal expression, independent of the values of the variables in the expression. –Run-time errors: logic errors that result in an illegal expression for specific values of the data (harder to fix) –Logic errors that result in the program executing completely, but the answer that they return is incorrect (hardest to fix).

3
Syntax Error Example An M-file contains: x = 7; y = 8; if x = y x = y$2 else x = y(3 end Running at the command prompt gives: >> temp ??? Error: File: C:\Programs\MATLAB6p5\work\temp.m Line: 3 Column: 6 Assignment statements do not produce results. (Use = = to test for equality.)

4
Syntax Error Analysis Matlab only reported the first error it found. It gives you a link to the position in the files where the error occurred. It tells you what type of error (assignment statements do not produce results). And it suggests a fix (use == to test for equality).

5
Runtime Errors x = [1 2 3 4]; y = magic(2); % subtraction will cause an error - x is 2-D. xn = x – y; ??? Error using ==> minus Matrix dimensions must agree. Error in ==> temp at 4 z = x - y;

6
Runtime Error Analysis Matlab gives the line number that caused the error (sometimes errors can propagate) – Also gives the reason for the runtime error! Runtime errors can often times be found manually – harder problems rely on the debugger

7
Logic Errors %print odd numbers from 1 to 10 for i = 1:10 if rem(i,2) == 0 disp(i); end Simple example, but can be very hard to track down Good debugging techniques come in handy here Simple example, but can be very hard to track down Good debugging techniques come in handy here

8
Debugger Example type modes type edit modes use breakpoints to walk through code – try the keyboard command

9
Handling Errors Yourself try-catch: – http://www.mathworks.com/help/techdoc/ref/cat ch.html http://www.mathworks.com/help/techdoc/ref/cat ch.html

10
Decent Debugging Tutorials http://www.youtube.com/watch?v=9iTj-- Q6ZRE http://www.youtube.com/watch?v=9iTj-- Q6ZRE https://engineering.purdue.edu/ECN/Support /KB/Docs/DebuggingMatlabMfile https://engineering.purdue.edu/ECN/Support /KB/Docs/DebuggingMatlabMfile

11
Additional Resources https://ceprofs.civil.tamu.edu/ssocolofsky/engr111a/Downloads/Lectures/Class%201 2.1%2004c%20Version%20A.ppt http://jagger.berkeley.edu/~pack/e77/Debugging.ppt

Similar presentations

OK

Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 4: Enhancing Your Program.

Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 4: Enhancing Your Program.

© 2018 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on phonetic transcription translator Ppt on life cycle of a star Ppt on child labour in hindi Ppt on production planning Ppt on communication skills for nurses Ppt on electricity for class 10th math Download maths ppt on number system for class 9 Ppt on mammals and egg laying animals called Ppt on abo blood grouping principle Ppt on current trends in information technology