passing function handle to separate function m-file error
이전 댓글 표시
Hi,
I have a function (function-1) which passes a function handle of the form:
fhandle = @fun; % step-1
to a function in a separate m-file (function-2). I invoke this function handle in function-2 using:
res = feval(fhandle, ...); % step-2
where the function in 'fhandle' is defined as a separate non-nested function within the function-2 m-file (function-2-1). However, this gives the following error:
"Undefined function 'fun' for input arguments of type 'double'."
I have also tried invoking the function handle directly, which also gives the same error:
res = fhandle(...); % step-2-v.2
This is odd, as if I go into function-2 in debug mode and re-enter the code in step-1 again, and then re-run step-2 and step-2-v.2, it seems to evaluate the function just fine. A work-around I have found is by defining the function handle as a string:
fhandle = 'fun'; % step-1-v.2
which seems to work fine. However, I have read that it is better practice to use the function handle form @, rather than passing a string. Could this be a bug or am I missing something?
Thanks
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Desktop에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!