23.12.2012 Views

MATLAB Function Reference Volume 1: A - E - Bad Request

MATLAB Function Reference Volume 1: A - E - Bad Request

MATLAB Function Reference Volume 1: A - E - Bad Request

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Examples The file buggy, used in these examples, consists of three lines.<br />

function z = buggy(x)<br />

n = length(x);<br />

z = (1:n)./x;<br />

Example 1 – Stop at First Executable Line<br />

The statements<br />

dbstop in buggy<br />

buggy(2:5)<br />

stop execution at the first executable line in buggy<br />

n = length(x);<br />

The function<br />

dbstep<br />

advances to the next line, at which point, you can examine the value of n.<br />

dbstop<br />

Example 2 – Stop if Error<br />

Because buggy only works on vectors, it produces an error if the input x is a full<br />

matrix. The statements<br />

dbstop if error<br />

buggy(magic(3))<br />

produce<br />

??? Error using ==> ./<br />

Matrix dimensions must agree.<br />

Error in ==> c:\buggy.m<br />

On line 3 ==> z = (1:n)./x;<br />

K»<br />

and put <strong>MATLAB</strong> in debug mode.<br />

2-391

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!