Preserve variable names
Variable names to preserve in the generated code
Description
App Configuration Pane: Advanced
Configuration Objects: coder.MexCodeConfig | coder.CodeConfig | coder.EmbeddedCodeConfig
The Preserve variable names parameter specifies which variable names the code generator must preserve in the generated code.
By default, when possible, variables share names and memory in the generated code. The code generator reuses your variable names for other variables or reuses other variable names for your variables. If your code uses large structures or arrays, this default behavior can reduce memory usage or improve execution speed.
If code readability is more important than reduced memory usage, specify that you want
the code generator to preserve your variable names rather than reuse them in the
generated code.. To do this, set the Preserve variable names
parameter to User names. Then, you can more easily trace the
variables in the generated code back to the variables in your MATLAB® code.
Settings
NoneThe code generator does not have to preserve any variable names. It can reuse any variables that meet the requirements for variable reuse. This value is the default value.
AllPreserve all variable names. This parameter value disables variable reuse. Use this option only for testing or debugging, not for production code.
User namesThe code generator preserves names that correspond to variables that you define in the MATLAB code. It does not replace your variable name with another name and does not use your name for another variable. This setting does not prevent an optimization from removing your variables from the generated code or prevent the C/C++ compiler from reusing the variables in the generated binary code.
Programmatic Use
Property:
PreserveVariableNames |
Values: 'None' |
'UserNames' | 'All' |
Default: 'None' |
Examples
Preserve Your Variable Names in Generated Code
Consider this MATLAB code snippet:
if (s > 0) myvar1 = 0; ... else myvar2 = 0; ... end
By default, the generated code can look like this code:
if (s > 0.0) {
myvar2 = 0.0;
...
} else {
myvar2 = 0.0;
...
}
When you set the Preserve variable names parameter to
User names, the generated code can look like this
code:
if (s > 0.0) {
myvar1 = 0.0;
...
} else {
myvar2 = 0.0;
...
}Version History
Introduced in R2015a