Create function handle from function file
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Arthur Roué
am 10 Mär. 2020
Kommentiert: tommsch
am 30 Nov. 2020
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 Kommentare
Akzeptierte Antwort
Star Strider
am 10 Mär. 2020
Bearbeitet: Steven Lord
am 10 Mär. 2020
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 Kommentare
tommsch
am 30 Nov. 2020
@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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Performance and Memory finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!