Simulink Code Generator - Preserve User Names

2 views (last 30 days)
Simon C
Simon C on 12 Apr 2021
Commented: Simon C on 28 Apr 2021
Using Version 2018b, is there a way to use the "Preserve User Names" for "code" in a MATLAB function (as the help indicates is in the MATLAB encoder for code generation)?
Looking at the code generated out of the Simulink Code generation, I can see that it makes decisions on removing locally declared variables. These have been added to avoid repeating calculations throughout the script therefore reducing the number of function calls required. However, when these are optimised in code generation, the labels are used in a different order meaning the code is now misleading . Now this could be fixed by not using meaningful names in the Matlab function script in the first place, but that's not acceptable really. When I have to debug this code, I want to be able to read it as intended.

Answers (1)

Meghna Chatterjee
Meghna Chatterjee on 14 Apr 2021
Hi Simon,
To control the names of the structures in the generated code, you need an Embedded Coder® license. To instead store a data item in a separate global variable whose name, file placement, and other characteristics you can control, you can apply a storage class to a signal, state, or Simulink.Parameter object. See C Code Generation Configuration for Model Interface Elements and Configuring Data Accessibility for additional explanation and steps.
  1 Comment
Simon C
Simon C on 28 Apr 2021
Thanks, this is a problem when using Matlab script in a function block, so nothing needs to be saved to the Workspace and is not using external structures or the parameters. Really just pointing out that the 'optimisation of local variables' in the code generation should be able to be turned on/off, in order to maintain the intent of the script in the function block.

Sign in to comment.

Categories

Find more on Simulink Coder in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!