MATLAB: Comments for Simulink signals and states do not appear in the C code.

Embedded Coder

I am making a control algorithm model in Simulink from which I want to generate readable (and highly-efficient) C code. I want to add comments in the generated C code for certain Simulink signals and states. I have tried to apply the method shown in the demo model 'rtwdemo_comments', but despite many attempts, I still have not managed to realize the comments in the C code.
In my model, I have added a description for the Simulink.Signal objects corresponding to a certain state and a signal, but the description does not pop up as a comment in the generated C code. How can this be accomplished?

Best Answer

The reason that your comments are not appearing in the generated code is due to the storage classes you have chosen for the Simulink.Signal objects. When the storage class is set to 'Auto', the data elements are subject to code generation optimizations. Since these Simulink.Signal objects are not declared on their own in the code, their comments do not make it into the generated code. The following link discusses adding comments to the generated code a bit more:
By changing the storage classes for your Simulink.Signal objects, you should be able to get the comments to appear in the generated code. For example, if you change the Simulink.Signal object which represents the signal to have a storage class of 'ExportedGlobal', you will notice that now a variable is declared for that object and the comment exists. For more information about different types of storage classes, please refer to the following link:
Please note that in order to use storage classes other than 'Auto', the Simulink.Signal must be defined outside of the model workspace (it should be in the base workspace).
If you are curious about how the generated code will store internal signal, state, and parameter data by default, please read through the following link: