Function Handle Limitations for Code Generation
R2026bWhen you use function handles in MATLAB® code intended for code generation, adhere to the following restrictions:
In some cases, using the same variable to reference different function handles causes a compile-time error. For example, this code does not compile:
function y = foo(p) x = @plus; if p x = @minus; end y = x(1, 2);
You cannot pass function handles as inputs to or outputs from coder.ceval (MATLAB Coder). For example, suppose that f and str.f are
function handles:
f = @sin; str.x = pi; str.f = f;
The following statements result in compilation errors:
coder.ceval('foo', @sin);
coder.ceval('foo', f);
coder.ceval('foo', str);
You cannot create a function handle that references an extrinsic MATLAB function.
You cannot pass function handles to or from feval and other extrinsic MATLAB functions.
You cannot pass function handles as inputs to or outputs from entry-point functions. For example, consider this function:
function x = plotFcn(fhandle, data) assert(isa(fhandle,'function_handle') && isa(data,'double')); plot(data, fhandle(data)); x = fhandle(data);
In this example, the function plotFcn receives
a function handle and its data as inputs. plotFcn attempts
to call the function referenced by the fhandle with
the input data and plot the results. However, this
code generates a compilation error. The error indicates that the function isa does
not recognize 'function_handle' as a class name
when called inside a MATLAB function to specify properties of
inputs.
You cannot display or watch function handles from the debugger. The function handles appear as empty matrices.
You can use function handles in a MATLAB Function block. You cannot use function handles for Simulink® signals, parameters, or data store memory.
See Also
Topics
- Using Extrinsic Functions (MATLAB Coder)
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Website auswählen
Wählen Sie eine Website aus, um übersetzte Inhalte (sofern verfügbar) sowie lokale Veranstaltungen und Angebote anzuzeigen. Auf der Grundlage Ihres Standorts empfehlen wir Ihnen die folgende Auswahl: .
Sie können auch eine Website aus der folgenden Liste auswählen:
So erhalten Sie die bestmögliche Leistung auf der Website
Wählen Sie für die bestmögliche Website-Leistung die Website für China (auf Chinesisch oder Englisch). Andere landesspezifische Websites von MathWorks sind für Besuche von Ihrem Standort aus nicht optimiert.
Amerika
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)