What is the difference between Function and Function Handle?
17 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Sandeep Ramini
am 11 Dez. 2018
Bearbeitet: Stephen23
am 11 Dez. 2018
Hello, I have to use lsqnonlin and cannot use function(Objective Function to be minimized). But it only accepts Function Handles but not direct Function calls. I tried to search on various sources but the Idea isn't clear. Can someone please explain me?
Thank you,
0 Kommentare
Akzeptierte Antwort
Stephen23
am 11 Dez. 2018
Bearbeitet: Stephen23
am 11 Dez. 2018
A function is some code written in a file, starting with the function keyword. When you call that function then MATLAB will run that code.
A function handle is a variable in the MATLAB workspace which is a handle to a particular function (which could be in a file, or an anonymous function). Because a function handle is a variable it can be passed around just like any other variable. This is particularly useful when used as an input argument to another function (e.g. as the objective function for optimization functions).
Function handles are one of the fundamental variable classes in MATLAB:
Function handles are created using the @ character, e.g.:
myfun = @sin % handle to SIN function
myfun = @(x)sqrt(x)+5 % handle to anonymous function
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Function Handles 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!