15.11.2014 Views

Chapter 4: Programming in Matlab - College of the Redwoods

Chapter 4: Programming in Matlab - College of the Redwoods

Chapter 4: Programming in Matlab - College of the Redwoods

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Section 4.1 Logical Arrays 295<br />

Elim<strong>in</strong>ate complex numbers from<br />

<strong>the</strong> matrix z.<br />

k=real(z)~=z;<br />

z(k)=NaN;<br />

Open a new figure w<strong>in</strong>dow and<br />

replot <strong>the</strong> surface.<br />

figure<br />

mesh(x,y,z)<br />

35. Def<strong>in</strong>e <strong>the</strong> anonymous function.<br />

f=@(x,y) 12-x-y;<br />

Set up <strong>the</strong> grid.<br />

x=l<strong>in</strong>space(-3,3,40);<br />

y=x;<br />

[x,y]=meshgrid(x,y);<br />

Evaluate <strong>the</strong> function at each (x, y)<br />

pair <strong>in</strong> <strong>the</strong> grid.<br />

z=f(x,y);<br />

Determ<strong>in</strong>e where x > −1 and<br />

set all entries <strong>in</strong> z equal to NaN where<br />

this contra<strong>in</strong>t is not satisfied.<br />

k=x>-1;<br />

z(~k)=NaN;

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

Saved successfully!

Ooh no, something went wrong!