| Contents | Index |
| On this page… |
|---|
Pointers for Signals and Parameters Using Simulink Data Objects |
To create a pointer in the generated code, you can configure a signal to use the ImportedExternPointer storage class or use an mpt.Signal (or mpt.Parameter for parameters) object with an ImportedExternPointer storage class.
extern double *u1;
This is a quick method to obtain pointers in the generated code. You cannot control the data type, which is decided by the model compilation process.
Create the ex_pointer_signal model using the blocks shown and follow the steps to configure the signals and model.

Label the signal to be imported as a pointer, in this example, u1.
Right-click the u1 signal line and select Signal Properties.
Select the Code Generation tab and specify the Storage Class parameter as ImportedExternPointer.
Click OK.
Press Ctrl+B to generate code.
The generated code includes the extern declaration for the pointer in the ex_pointer_signal_private.h file.
extern real_T *u1;
extern double *u1;
You can control the data type by using a Simulink data object to generate a pointer. You can use this procedure for either a signal or parameter. To create a pointer for a parameter, use an mpt.Parameter instead of an mpt.Signal data object described in step 3.
Create the ex_pointer_signal_data_object model using the blocks shown and follow the steps to configure the signals and model.

Label the signal to be imported as a pointer, in this example, u1.
At the MATLAB command line, create a data object for signal u1.
u1 = mpt.Signal;
In the base workspace, double-click u1 to open the mpt.Signal dialog box.
Specify the Storage class parameter as ImportedExternPointer.
Click Apply and OK.
Press Ctrl+B to generate code.
The generated code includes the extern declaration for the pointer in the ex_pointer_signal_data_object_private.h file.
extern real_T *u1;
The ex_pointer_signal_data_object_private.h file imports the pointer into the generated code. To compile the code, you must declare and define the pointer in the main program.
![]() | Arrays | Variant Systems | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |