Hauptinhalt

Daten variabler Größe

Codegenerierung für Arrays, deren Größe sich im generierten Code ändert

Während der Codegenerierung identifiziert der Codegenerator Arrays, einschließlich Skalare, Vektoren und Matrizen, als Arrays mit fester oder variabler Größe.

  • Der Codegenerator kennzeichnet ein Array als variable Größe, wenn er die Größe des Arrays nicht bestimmen kann oder wenn sich die Größe des Arrays ändert.

  • Der Codegenerator kennzeichnet ein Array als feste Größe, wenn er feststellen kann, dass sich die Größe des Arrays nicht ändert.

Wenn Sie verstehen, wie der Codegenerator Arrays mit fester und variabler Größe verarbeitet, können Sie Fehler während der Codegenerierung besser diagnostizieren und beheben. Wenn Ihre Anwendung keine Arrays mit variabler Größe erfordert, können Sie auch die Variablengröße und die dynamische Speicherzuweisung optimieren, um die Leistung des generierten Codes zu verbessern.

Funktionen

coder.areUnboundedVariableSizedArraysSupportedCheck if current configuration settings allow unbounded variable-size arrays (Seit R2024a)
coder.varsizeResolve size incompatibility errors and declare upper bounds

Grundlagen der variablen Dimensionierung

Generate Code for Variable-Size Arrays

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

Code Generation for Arrays That Grow Via end+1 Indexing

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

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

Incompatibilities with MATLAB in Variable-Size Support for Code Generation

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

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

Dynamische Speicherzuweisung

Control Dynamic Memory Allocation in Generated Code

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

Generate Code with Implicit Expansion Enabled

The code generator introduces modifications in the generated code to accomplish implicit expansion.

Optimize Implicit Expansion in Generated Code

Implicit expansion in the generated code is enabled by default.

Representation of Arrays in Generated Code

Understand how arrays are represented in the generated code.

Use Dynamically Allocated C Arrays in the Generated Function Interfaces

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

Use Dynamically Allocated C++ Arrays in Generated Function Interfaces

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

Fehlersuche

Fehler beheben: Die Arrays weisen inkompatible Größen auf

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

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

Resolve Error: coder.varsize Not Supported for Strings

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

Resolve Error: coder.varsize Not Supported for Class Properties

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

Resolve Error: Unable to Produce Column Vector from Scalar

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

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.