Reuse Large Arrays and Structures - MATLAB & Simulink (original) (raw)

Main Content

Variable reuse can reduce memory usage or improve execution speed, especially when your code has large structures or arrays. However, variable reuse results in less readable code. If reduced memory usage is more important than code readability, specify that you want the code generator to reuse your variables in the generated code.

The code generator can reuse the name and memory of one variable for another variable when:

The code generator reuses your variable names for other variables or reuses other variable names for your variables. For example, for code such as:

if (s>0) myvar1 = 0; ... else myvar2 = 0; ... end

the generated code can look like this code:

if (s > 0.0) { myvar2 = 0.0; ... } else { myvar2 = 0.0; ... }

To specify that you want the code generator to reuse your variables:

See Also

Topics