Variable-Size Data
During acceleration and fixed-point conversion, the code generator identifies arrays, including scalars, vectors, and matrices, as either fixed size or variable size.
The code generator designates an array as variable size if it cannot determine the size of the array or if the size of the array changes.
The code generator designates an array as fixed size if it can determine that the size of the array does not change.
Understanding how the code generator handles fixed- and variable-size arrays can help you to diagnose and fix errors during code generation. If your application does not require variable-size arrays, you can also fine-tune variable sizing and dynamic memory allocation to potentially improve the performance of the generated code.
Functions
coder.areUnboundedVariableSizedArraysSupported | Check if current configuration settings allow unbounded variable-size arrays (Since R2024a) |
coder.varsize | Resolve size incompatibility errors and declare upper bounds |
Topics
- 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. - 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.
- 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.
Troubleshooting
Resolve Error: Arrays Have Incompatible Sizes (MATLAB Coder)
Troubleshoot size incompatibility errors that occur during code generation.
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.
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.