Main Content

Specify Data Types for an Edit Parameter Using Data Type Parameter

You can specify the acceptable data types for a mask edit parameter with a data type parameter. Associating a data type for the edit parameter defines a rule for the input value that can be provided through the mask dialog box. You can also use the datatype parameter to associate the minimum and maximum value for the edit parameter. You can use datatype parameter to do fixed-point analysis.

Explore the Model

The model demonstrates all the mask parameter types. Use the block DataTypeStr for specifying data types and minimum and maximum values for an edit parameter. The masked block DataTypeStr has an edit parameter Gain, a min parameter Minimum, a max parameter Maximum, and a data type parameter DataTypeStrParameter.

open_system("slexMaskParameterOptionsExample.slx")

Associate Data Types to an Edit Parameter

The block DataTypeStr is masked and the required parameters are created. Follow these steps if you want to create a similar model.

1. Open the masked block DataTypeStr.

2. Create an edit parameter Gain, a min parameter Minimum, a max parameter Maximum, and a data type parameter DataTypeStrParameter.

3. To specify the allowed data types and minimum and the maximum values for the Gain parameter, select Data Type parameter in the Parameter pane and then double-click Type options in the Property Editor pane. The type options editor opens. The type options editor has these tabs that you can use to specify data types for the selected parameter:

  • Inherit rules — Specify inheritance rules for determining the data types. The inheritance rules are grouped under three categories: Common Simulink rules, Custom rules, and Advanced Simulink rules. The Advanced rules section allows you to inherit rules from the blocks such as Lookup table, Constant, and Gain. For example, breakpoint data, constant value, gain, table data, logic data, accumulator, product output, and Simulink. It also allows you to have same word length as input and have same data types for all ports. The Custom rules section lists any custom inheritance rules registered on the MATLAB™ search path. For definitions of some Inheritance rules, see Data Type Inheritance Rules.

  • Associations — Associate a data type parameter with an Edit parameter. Select the a min parameter Minimum, a max parameter Maximum in Design minimum and Design maximum to associate the minimum and maximum parameter to the edit parameter Gain parameter.

4. Click OK in the Type Options editor to save the rules selection.

5. Click Save Mask to save the mask.

Note: Setting the acceptable datatypes through the data type parameter does not set the signal attribute or output data type for the associated edit parameter. Explicitly set the data type associated with the edit parameter directly on the underlying block of the masked subsystem that uses the edit parameter.

Associate Data Type to an Edit Parameter Programmatically

1. Create a mask on the current model.

maskObj = Simulink.Mask.get(gcb);

2. Create edit, min, and max parameters.

maskObj.addParameter('Name','Gain', 'Type','edit');
maskObj.addParameter('Name','minimum', 'Type','min');
maskObj.addParameter('Name','maximum', 'Type','max');

3. Add a data type parameter and associate it to the edit parameter Gain.

maskObj.addParameter('Name','DataType',...
'Type','unidt({a=DataType|Min|Max|Gain}{i=Inherit: auto|Inherit:Inherit via internal rule}{b=double|single})');

Where, Type displays the values specified for the DataType parameter and has these definitions:

  • The associations are defined by a.

  • Inherit rules are defined by i and its corresponding value is Inherit: Same as first input.

  • Built-in types are defined by b and its corresponding value are double and single.

See Also