この質問はすでにここで尋ねられ、回答されていることは知っていますが、うまくいきません。
私は単純な関数 f1 を持っています:
function out = f1(x)
out = x^2 + 5;
end
関数名を入力として受け取る「デリゲート」関数が必要です。以下に、私の 2 つのトライアルを示します。
% function out = delegate_function(the_input , func_handle)
% out = func2(the_input, func_handle);
% end
function out = delegate_function(the_input , funcname)
thefunc = str2func(funcname);
out = thefunc(the_input);
end
コマンドウィンドウでこれを呼び出すと、どちらも同じエラーが発生します。
delegate_function(2 , f1); % I want ans = 9
Error using f1 (line 2)
Not enough input arguments.
私は何を間違っていますか?
助けてくれてありがとう!