Create function handle from function file
조회 수: 9 (최근 30일)
이전 댓글 표시
Is it possible to create a function handle from function file ? In other words, create a function_handle object @foo from file foo.m.
댓글 수: 0
채택된 답변
Star Strider
2020년 3월 10일
편집: Steven Lord
2020년 3월 10일
Yes!
In some instances, that is necessary in order to evaluate the function.
Example —
function y = f(x)
y = x.^2 - 2;
end
fz = fzero(@f,1)
produces:
fz =
1.4142
[SL: typo fix]
댓글 수: 8
tommsch
2020년 11월 30일
@Steven Lord
The function for which you want to create the function handle must be in scope when the function handle is created. It does not need to be in scope when the function handle is evaluated.
When the function is shadowed by another function later on, the function handle may point to another function.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Performance and Memory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!