MATLAB: How to make each input and output be a separate structure in Embedded coder code

Embedded Coder

I am generating code from a Simulink model. When I generate code for a subsystem with multiple inports and outports, all of the inports are assigned to a single structure in the code and all of the outputs are assigned to another structure. Is there any way to separate the inputs and outputs to different structures?

Best Answer

You may store each input and output signal in a separate structure by setting the input and output signals' "Storage Class" to "ExportedGlobal".
To do this in Simulink R2015b, do the following:
1. Right click on the signal.
2. In the "Signal Properties" dialog box, ensure that the "Signal name" is filled in.
3. On the "Code Generation" tab, select "Package: Simulink" and "Storage Class: ExportedGlobal".
To do this in Simulink R2017b, do the following:
1. In the model menu bar, click on "View" -> "Model Data."
2. In the "Model Data" window top left corner drop down menu, select "Code".
3. In the "Inports/Outports" tab, set the "Storage Class" to "ExportedGlobal"
You may customize the code in this way if you are using Embedded Coder (".ert" taget), but you may not do this when you are using the more basic Simulink Coder (".grt" target).
You may find more information on the ExportedGlobal storage class at the links below: