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.

Function Handles<br />

isequal(h1, h2)<br />

ans =<br />

1<br />

[q1 q2] = test_eq(3, -1, 2);<br />

isequal(q1, q2)<br />

ans =<br />

1<br />

The answer makes sense because h1 and h2 will always produce the same<br />

answer:<br />

x = h1(),<br />

x =<br />

418<br />

y =<br />

418<br />

y = h2()<br />

However, handles constructed on different calls to the parent function are<br />

not equal:<br />

isequal(h1, q1)<br />

ans =<br />

0<br />

In this case, h1 and q1 behave differently:<br />

x = h1(),<br />

x =<br />

418<br />

y =<br />

30<br />

y = q1()<br />

Handles Saved to a MAT-File<br />

If you save equivalent anonymous or nested function handles to separate<br />

MAT-files and then load them back into the <strong>MATLAB</strong> workspace, they are no<br />

longer equal. This is because saving the function handle in effect loses track<br />

of the original circumstances under which the function handle was created,<br />

and reloading it results in a function handle that compares as being unequal<br />

to the original function handle.<br />

4-29

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

Saved successfully!

Ooh no, something went wrong!