23.06.2015 Views

MATLAB Programming

MATLAB Programming

MATLAB Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

4 M-File <strong>Programming</strong><br />

Create two equivalent anonymous function handles:<br />

h1 = @(x) sin(x);<br />

h2 = h1;<br />

isequal(h1, h2)<br />

ans =<br />

1<br />

Save each to a different MAT-file:<br />

save fname1 h1;<br />

save fname2 h2;<br />

Clear the <strong>MATLAB</strong> workspace and then load the function handles back into<br />

the workspace:<br />

clear all<br />

load fname1<br />

load fname2<br />

The function handles are no longer equal:<br />

isequal(h1, h2)<br />

ans =<br />

0<br />

Note however that equal anonymous and nested function handles that you<br />

savetothesameMAT-fileareequalwhenloadedbackinto<strong>MATLAB</strong>:<br />

h1 = @(x) sin(x);<br />

h2 = h1;<br />

isequal(h1, h2)<br />

ans =<br />

1<br />

save fname h1 h2;<br />

clear all<br />

load fname<br />

4-30

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

Saved successfully!

Ooh no, something went wrong!