Passing a constant function handle to another function
Show older comments
I want to pass a constant function handle "simulate" to a function "fftest", so that the corresponding function in the function handle simulate is called during evaluation "fftest" with the provided arguments:
simulate = @depsim;
g = @(x,y) fftest(x,y,@simulate);
g(1,1);
% in separate files:
function ret = depsim(a,b)
ret = ones(a,b);
end
function fftest(a,b,simulate)
disp(simulate(a,b));
disp("it works!");
end
I get the following exception, when I run the code:
Not enough input arguments.
Error in depsim (line 3)
ret = ones(a,b)
Error in test (line 28)
simulate = depsim;
I do not understand what the problem is, do I need to pass the handle differently?
Accepted Answer
More Answers (0)
Categories
Find more on Historical Contests in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!