Main Content

Arrays for Signals

C Construct

double myIn[5];
double myOut[5];

Procedure

1. Open example model ex_signal_array.

2. In the Model Data Editor, select the Inports/Outports tab.

3. From the Change View drop-down list, select Design.

Observe these settings:

  • For the Inport block, the Signal Name is myIn and Dimensions is [5 1].

  • For the Outport block, the Signal Name is myOut.

4. Open the Embedded Coder app.

5. In the C Code tab, select Code Interface > Individual Element Code Mappings.

6. In the Code Mappings editor, on the Inports tab, for the Inport block and the Outport block, the Storage Class is ExportedGlobal. With this setting, the blocks appear in the generated code as separate global variables.

7. To build the model and generate code, press Ctrl+B.

Results

The generated source file ex_signal_array.c defines the global variables myIn and myOut as arrays with 5 elements each.

/* Exported block signals */
real32_T myIn[5];                      /* '<Root>/In1' */
real32_T myOut[5];                     /* '<Root>/Out1' */

Related Topics