Main Content

Specify Data Types Using DataTypeStr Parameter

Similar to any mask parameter, the DataType parameter can be added on a mask dialog box from the Mask Editor. Adding the DataType parameter to the mask dialog box allows the end user of the block to specify the acceptable data types for the associated Edit type parameter. While defining the mask, you can specify single or multiple data types for the Edit parameter. The end user of the block can select from one of these data types. Specifying a data type for the Edit parameter defines a rule for the input value that can be provided through the mask dialog box.

The DataType parameter also allows you to specify a minimum and maximum value for the Edit parameter. You can do so by using the Min and Max mask parameters and associating these parameters to the DataType parameter. DataType parameter can be used to do fixed-point analysis.

Associate Data Types to Edit Parameter

  1. Open the model in which you want to mask a block. For example, open the DataTypeStr model in Types of Mask Parameters.

  2. Select the Subsystem block on the Subsystem Block tab, in the Mask group, click Create Mask.

    Note

    If you are editing an existing mask, to open the Mask Editor, on the Subsystem Block tab, in the Mask group, click Edit Mask.

  3. In the Mask Editor, click the Parameters & Dialog pane and add the Edit, Min, Max, DataType parameters.

    datatypestr

  4. To specify data types for the Edit parameter, select DataType in the Dialog box section of the Mask Editor and click the button next to Type options in the Property editor pane. The Type options editor has a tabbed user interface containing these tabs for data type rules.

    1. Inherit rules- Specify inheritance rules for determining the data types. The inherit rules are grouped under three categories: Common Simulink® rules, Custom rules, and Advanced Simulink rules. By default, the Common Simulink rules and Advanced Simulink rules are available under Inherit rules tab. The Advanced rules section allows you to inherit rules from 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 are listed under Inherit rules tab only if there are any custom inheritance rules registered on the MATLAB® search path. For definitions of some Inherit rules, see Data Type Inheritance Rules.

      parameters for selected types

    2. Built-in types: Specify one or more built-in Simulink data types, such as double or single. For more information, see Data Types Supported by Simulink.

      data types

    3. Fixed-point: Specify the scaling and signed modes for a fixed-point data type. For more information, see Specifying a Fixed-Point Data Type.

      type options

    4. User-defined: Specify a bus object, an enumerated (enum) data type, or a string. For more information, see Specify an Enumerated Data Type, Specify a Bus Object Data Type, and Simulink Strings.

      horizontal stretch property

    5. Associations: Associate a data type parameter with an Edit parameter. You can also associate the Min and Max parameters to the Edit parameter.

      data type association

  5. To save the rules selection, click OK in the Type Options Editor.

  6. To save changes and exit the Mask Editor, click OK.

View DataTypeStr Programmatically

You can use the Simulink.Mask.get command in the MATLAB command window to view the data type values specified for a block mask. MATLAB uses a predefined nomenclature to represent the data type information in the command line.

To view the DataTypeStr Parameter for the example model programmatically, explore the modelTypes of Mask Parameters .

maskobj = Simulink.Mask.get(gcb)
maskobj = 

Mask with properties:

                  Type: ''
                  Description: ''
                         Help: ''
               Initialization: ''
               SelfModifiable: 'off'
                      Display: ''
                    IconFrame: 'on'
                   IconOpaque: 'opaque'
         RunInitForIconRedraw: 'off'
                   IconRotate: 'none'
                   PortRotate: 'default'
                    IconUnits: 'autoscale'
                   Parameters: [1×4 Simulink.MaskParameter]
                     BaseMask: [0×0 Simulink.Mask]
         ParameterConstraints: [0×0 Simulink.Mask.Constraints]
         BlockConstraintRules: [0×0 Simulink.Mask.BlockConstraints]
    ConstraintParamAssociator: [0×0 Simulink.Mask.ConstraintParamAssociator]

maskobj.getParameter('DataTypeStrParameter')
ans = 

MaskParameter with properties:

Type: 'unidt({a=4|2|3|1}{i=Inherit: auto|Inherit: Inherit via internal rule}{b=double|single})'
    TypeOptions: {0×1 cell}
           Name: 'DataTypeStrParameter'
         Prompt: 'Output data type'
          Value: 'Inherit: auto'
       Evaluate: 'on'
        Tunable: 'off'
      NeverSave: 'off'
         Hidden: 'off'
       ReadOnly: 'off'
        Enabled: 'on'
        Visible: 'on'
    ShowTooltip: 'on'
       Callback: ''
          Alias: ''

The result displays the properties that are defined for the DataTypeStr parameter. This example defines the nomenclature for the specified type options:

Type: 'unidt({a=4|2|3|1}{i=Inherit: auto|Inherit: Inherit via internal rule}{b=double|single})'

Here, Type displays the values specified for the DataTypeStr parameter and has these definitions:

  • a defines Associations and its corresponding values are 4, 2, 3, 1. These values are index numbers for the parameter and represent the DataTypeStr, Min, Max, and Edit parameters sequentially.

  • i defines the Inherit rules and its corresponding value as Inherit: Same as first input.

  • b defines the Built-in types and its corresponding value as double and single.

See Also