Hauptinhalt

Funktionsdefinition

R2026b
Definieren und Abrufen für die Codebeschleunigung

Bei der Erstellung von MATLAB®-Funktionen zur Verwendung für die Festkomma-Beschleunigung müssen mehrere Aspekte berücksichtigt werden. Hierzu gehören bestimmte Einschränkungen bei der Verwendung von varargin und varargout, rekursiver Funktionen, anonymer Funktionen und verschachtelter Funktionen. Um Code für rekursive MATLAB Funktionen zu generieren, verwendet der Code-Generator entweder Kompilierzeit- oder Laufzeit-Rekursion. Um effizienten C/C++ Code zu erzeugen, erstellt der Code-Generator manchmal mehrere Versionen einer Funktion, die als Funktionsspezialisierungen bezeichnet werden. In bestimmten Fällen können Sie den Code-Generator mithilfe coder.ignoreConst (MATLAB Coder) daran hindern, Funktionsspezialisierungen zu erstellen. Beim Erstellen einer MEX-Funktion können Sie die Codegenerierung für eine bestimmte Funktion in Ihrem MATLAB Programmcode umgehen und stattdessen die MATLAB-Engine zur Ausführung des Funktionsaufrufs verwenden. Verwenden Sie hierfür das Konstrukt coder.extrinsic.

Funktionen

coder.extrinsicDeclare extrinsic function
coder.ignoreConstPrevent use of constant value of expression for function specializations
coder.mustBeConstValidate that value is a compile-time constant (Seit R2023b)
coder.unrollUnroll for-loop by making a copy of the loop body for each loop iteration
coder.sameSizeBinaryOpApply element-wise binary operations without implicit expansion
coder.noImplicitExpansionInFunctionDisable implicit expansion within the specified function in the generated code
coder.readRead data files at run time in generated code (Seit R2023a)
coder.writeCreate data files that the generated code reads at run time (Seit R2023a)

Grundlagen der variablen Dimensionierung

Generate Code for Variable-Size Arrays (MATLAB Coder)

Learn how the code generator defines and handles fixed- and variable-size data.

Code Generation for Arrays That Grow Via end+1 Indexing (MATLAB Coder)

Code generation considerations when you use (end+1) or {end+1} to grow an array.

Specify Upper Bounds for Variable-Size Arrays in Generated Code (MATLAB Coder)

To avoid dynamic memory allocation, specify upper bounds for variable-size arrays.

Incompatibilities with MATLAB in Variable-Size Support for Code Generation (MATLAB Coder)

Understand how the behavior of the generated code can differ from MATLAB as a result of variable-size data.

Generate Code for a MATLAB Function That Expands a Vector in a Loop (MATLAB Coder)

Generate C and C++ code for a function that uses variable-size data with and without dynamically allocated memory.

Extrinsische Funktionen

Using Extrinsic Functions (MATLAB Coder)

Use MATLAB to execute a function call in the generated code.

Working With mxArray Outputs in Generated Code (MATLAB Coder)

Handle the mxArray objects returned by extrinsic functions.

Use Extrinsic Functions to Calibrate Data for Standalone Code Generation (MATLAB Coder)

Use MATLAB to execute function calls in the generated code.

Dynamische Speicherzuweisung

Control Dynamic Memory Allocation in Generated Code (MATLAB Coder)

Balance memory usage and performance by controlling dynamic memory allocation for fixed- and variable-size arrays.

Effects of Implicit Expansion on Generated Code (MATLAB Coder)

Implicit expansion in the generated code can affect output sizes, code size, and performance.

Representation of Arrays in Generated Code (MATLAB Coder)

Understand how arrays are represented in the generated code.

Use Dynamically Allocated C Arrays in the Generated Function Interfaces (MATLAB Coder)

Understand and use dynamically allocated arrays from the generated C function interfaces.

Use Dynamically Allocated C++ Arrays in Generated Function Interfaces (MATLAB Coder)

Understand and use dynamically allocated arrays from the generated C++ function interfaces.

Fehlersuche

Fehler beheben: Die Arrays weisen inkompatible Größen auf (MATLAB Coder)

Beheben von Fehlern aufgrund von Größeninkompatibilitäten, die bei der Codegenerierung auftreten

Resolve Error: Fixed Size on the Left Side but Variable Size on the Right (MATLAB Coder)

Troubleshoot errors when assigning variable-size arrays to fixed-size arrays.

Troubleshoot Replicated Functions in Generated Code (MATLAB Coder)

Troubleshoot duplicate functions in the generated code.

Resolve Error: Output Variable Must Be Assigned Before Run-Time Recursive Call (MATLAB Coder)

Troubleshoot error when the MATLAB code does not assign a value to an output variable before a recursive call.

Resolve Error: Compile-Time Recursion Limit Reached (MATLAB Coder)

Troubleshoot error when recursion during code generation exceeds the limit.

Resolve Error: coder.varsize Not Supported for Strings (MATLAB Coder)

Troubleshoot code generation error when using coder.varsize with string variables.

Resolve Error: coder.varsize Not Supported for Class Properties (MATLAB Coder)

Troubleshoot code generation error when using coder.varsize with properties of a MATLAB class.

Resolve Error: Unable to Produce Column Vector from Scalar (MATLAB Coder)

Troubleshoot error when an input argument that is a variable-length column vector at code generation time is a scalar at run time.

Resolve Error: Incorrect Size for Expression (MATLAB Coder)

Troubleshoot MEX function error when the size of an array at run time is incompatible with the size of the array in the generated code.