Use the programmatic interface to add and remove signals in the code mapping configuration of a Simulink model.
To interactively observe how your commands are reflected in the Code Mappings editor, make sure it is open with the Signals/States tab selected. To learn how to open the Code Mappings editor, see Open the Code Mappings Editor — C.
Open the model CoderMapAPI.
Use the function coder.mapping.api.get to retrieve the code mapping object of the model.
Get the handles of the output ports of the four Gain blocks and store them in variables.
Use the function addSignal to add the signal to the code mappings of the model. Set the storage class of sig_1 and sig_3 to ImportedExtern and the storage class of sig_2 and sig_4 to ImportedExternPointer. Update the model.
Use the slbuild command to generate code from the model.
Signals with ImportedExtern and ImportedExternPointer storage classes are declared in separate sections of the generated private header file of the model. Store the name of the private header file in the variable priv_h_file.
priv_h_file =
"CoderMapAPI_grt_rtw/CoderMapAPI_private.h"
The declarations of the signals appear as the following code in the header file:
/* Imported (extern) block signals */
extern real_T sig__1; /* '<Root>/gain_1' */
extern real_T sig__3; /* '<Root>/gain_3' */
extern real_T in_port_1; /* '<Root>/in_port_1' */
extern real_T in_port_2; /* '<Root>/in_port_2' */
/* Imported (extern) pointer block signals */
extern real_T *sig__2; /* '<Root>/gain_2' */
extern real_T *sig__4; /* '<Root>/gain_4' */
extern real_T *in_port_3; /* '<Root>/in_port_3' */
extern real_T *in_port_4; /* '<Root>/in_port_4' */
The signals are defined according to the specified storage classes.
To open the header file, enter this command in the MATLAB Command Window.
Use the function removeSignal to remove the first two signal lines from the code mappings of the model. Update the model.
Rebuild the model with the slbuild command.
The updated sections appear as the following code in the header file.
/* Imported (extern) block signals */
extern real_T sig__3; /* '<Root>/gain_3' */
extern real_T in_port_1; /* '<Root>/in_port_1' */
extern real_T in_port_2; /* '<Root>/in_port_2' */
/* Imported (extern) pointer block signals */
extern real_T *sig__4; /* '<Root>/gain_4' */
extern real_T *in_port_3; /* '<Root>/in_port_3' */
extern real_T *in_port_4; /* '<Root>/in_port_4' */
The removed signals no longer appear in the header file.