Compare Function Handles
Compare Handles Constructed from Named Function
MATLAB® considers function handles that you construct from the same named function to be equal.
The isequal function returns a value of true when comparing these types of handles.
fun1 = @sin;
fun2 = @sin;
isequal(fun1,fun2)
ans =
logical
1
If you save these handles to a MAT-file, and then load them back into the workspace, they are still
equal.
Compare Handles to Anonymous Functions
Unlike handles to named functions, function handles that represent the same anonymous function are
not equal. They are considered unequal because MATLAB cannot guarantee that the frozen values of
nonargument variables are the same. For example, in this case, A is a nonargument variable.
A = 5;
h1 = @(x)A * x.^2;
h2 = @(x)A * x.^2;
isequal(h1,h2)
ans =
logical
0
If you make a copy of an anonymous function handle, the copy and the original are equal.
h1 = @(x)A * x.^2;
h2 = h1;
isequal(h1,h2)
ans =
logical
1
13 Function Handles
13-8
Précédent

- 566/1450

Suivant