How can I tell Simulink Embedded Coder to get its variable names from my signal names, not the source block names?

12 views (last 30 days)
I am generating C code from a Simulink model using Simulink Embedded Coder with the ERT target. I can see that the variable names generated in the code are formatted according to the Configuration Parameters under the Code Generation/Symbols pane. For example, I am using $N$M for my local temporary variables. In the simplified cases, the mangle is unnecessary and the variable name is just the value of $N, "Name of object being identified."
If I have two signals, a and b entering a Sum block and producing a signal named c, the signal emerging from the Sum block corresponds to a generated variable named Sum. But in my mental model, signals are the variables and blocks are the functions/operations. So I would like the variable to be named c, not Sum.
How can I tell Simulink to inherit its variable names from the signal names, not the block names?
I am using MATLAB R2015a (64-bit) and Windows 7. I set up mex to use the Microsoft Visual C++ 2010 (C) compiler.

Answers (1)

Fangjun Jiang
Fangjun Jiang on 14 Jan 2019
Select the signal line, right click, select "Properties"
Provide the signal name (e.g. "c" ), check "Signal name must resolve to Simulink signal object"
Create the Simulink signal object in workspace or SLDD
c=Simulink.Signal or c=mpt.Signal
open c
Provide necessary parameters or just take the default value

Community Treasure Hunt

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

Start Hunting!