Arrays for Parameters
C Construct
float myParams[5]= {1.0F,2.0F,3.0F,4.0F,5.0F};
Procedure
1. Create the ex_param_array
model by using a Gain block.
2. In the model, select the Gain block. In the Property Inspector, set the value of the Gain parameter to myParam
.
3. Next to the parameter value, click the action button (the button with three vertical dots) and select Create.
4. In the Create New Data dialog box, set Value to Simulink.Parameter ([1 2 3 4 5])
. Click Create. A Simulink.Parameter
object, myParam
, appears in the base workspace. The Gain block uses the object to set the value of the Gain parameter.
5. In the Simulink.Parameter
property dialog box, set Storage class to ExportedGlobal
. Click OK.
With this setting, myParams
appears in the generated code as a separate global variable.
6. Set Data type to single
. Click OK.
7. To build the model and generate code, press Ctrl+B.
Results
The generated source file ex_param_array.c
defines and initializes the global variable myParams
.
/* Exported block parameters */ real32_T myParam[5] = { 1.0F, 2.0F, 3.0F, 4.0F, 5.0F } ;/* Variable: myParam * Referenced by: '<Root>/Gain' */