MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

h1 = @(x)A * x.^2;
h2 = h1;
isequal(h1,h2)


ans =


logical


1


Compare Handles to Nested Functions


MATLAB considers function handles to the same nested function to be equal only if your
code constructs these handles on the same call to the function containing the nested
function. This function constructs two handles to the same nested function.


function [h1,h2] = test_eq(a,b,c)
h1 = @findZ;
h2 = @findZ;


function z = findZ
z = a.^3 + b.^2 + c';
end
end


Function handles constructed from the same nested function and on the same call to the
parent function are considered equal.


[h1,h2] = test_eq(4,19,-7);
isequal(h1,h2)


ans =


logical


1


Function handles constructed from different calls are not considered equal.


Compare Function Handles
Free download pdf