Passing a constant function handle to another function
显示 更早的评论
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?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Historical Contests 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!