Variable-Size Data
You can specify variables in MATLAB Function and MATLAB System blocks as variable-size, which is data whose size is not known at compile time or changes at run time.
Blocks
MATLAB Function | Include MATLAB code in Simulink models |
MATLAB System | Include System object in model |
Functions
coder.areUnboundedVariableSizedArraysSupported | Check if current configuration settings allow unbounded variable-size arrays (Since R2024a) |
coder.varsize | Resolve size mismatch errors and declare upper bounds |
Topics
- Code Generation for Variable-Size Arrays
Variable-size data is data whose size is not known at compile time or whose size can change at run time.
- Declare Variable-Size MATLAB Function Block Variables
Allow variables defined in MATLAB Function blocks to change size during simulation.
- Unbounded Variable-Size Signals
Model unknown size data using dynamic arrays.
- Define Variable-Size Data for Code Generation
Choose a method for defining variable-size data.
- Use Dynamic Memory Allocation for Variable-Size Arrays in a MATLAB Function Block
Generate C/C++ code that uses dynamic memory allocation.
- Control Memory Allocation for Variable-Size Arrays in a MATLAB Function Block
Disable dynamic memory allocation or specify a dynamic memory allocation threshold for MATLAB Function blocks.
- Specify Upper Bounds for Variable-Size Arrays
To avoid dynamic memory allocation, specify upper bounds for a variable-size array.
- Incompatibilities with MATLAB in Variable-Size Support for Code Generation
Sometimes, the results for variable-size data in generated code are different than the results in MATLAB®.
- Variable-Sizing Restrictions for Code Generation of Toolbox Functions
Some restrictions for variable-size data apply to multiple toolbox functions.
Troubleshooting
Diagnose and Fix Variable-Size Data Errors
Troubleshoot size mismatch and upper bounds detection errors.
Resolve Issue: coder.varsize Not Supported for Strings
Troubleshoot code generation error when using coder.varisze
with string variables.