Function Handles
Function Handles sind MATLAB®-Datentypen, die eine Funktion repräsentieren. Function Handles dienen typischerweise dazu, eine Funktion auf eine andere Funktion zu übertragen. Beispielweise können Sie Function Handles als Eingabeargumente für Funktionen verwenden, die mathematische Ausdrücke über eine Reihe von Werten bewerten.
Function Handles können entweder benannte oder anonyme Funktionen sein. Verwenden Sie zum Erstellen von Function Handles den Operator @
. Zum Beispiel: Erstellen des Function Handle einer anonymen Funktion mit Bewertung des Ausdrucks x2 – y2:
f = @(x,y) (x.^2 - y.^2);
Funktionen
function_handle | Handle to function |
feval | Evaluate function |
func2str | Construct character vector from function handle |
str2func | Construct function handle from character vector |
localfunctions | Function handles to all local functions in MATLAB file |
functions | Information about function handle |
Themen
- Erstellen von Function Handles
Verwenden Sie ein Function Handle, um eine Verknüpfung mit einer benannten Funktion oder einer anonymen Funktion zu erstellen. Danach können Sie die repräsentative Funktion indirekt aufrufen.
- Eine Funktion einer weiteren Funktion übergeben
Sie können Function Handles als Eingabeargumente für Funktionen verwenden, die mathematische Ausdrücke über einen Wertebereich hinweg berechnen, wie zum Beispiel
integral
undfzero
. - Parameterizing Functions
This topic explains how to store or access extra parameters for mathematical functions that you pass to functions such as
fzero
,ode45
, orintegral
. - Call Local Functions Using Function Handles
If a function returns handles to local functions, you can call the local functions outside of the main function. This approach allows you to have multiple, callable functions in a single file.
- Compare Function Handles
The result of comparing equality of function handles depends on what the handle represents and when you created it.