Define or Edit Input Parameter Type by Using the App

Define or Edit an Input Parameter Type

The following procedure shows you how to define or edit double, single, int64, int32, int16, int8, uint64, uint32, uint16, uint8, logical, and char types.

For more information about defining other types, see the information in this table.

Input TypeLink
A string scalar (1-by-1 string array)Specify a String Scalar Input Parameter
A structure (struct)Specify a Structure Input Parameter
A cell array (cell (Homogeneous) or cell (Heterogeneous))Specify a Cell Array Input Parameter
A fixed-point data type (embedded.fi)Specify a Fixed-Point Input Parameter
An input by example (Define by Example)Define Input Parameter by Example by Using the App
A constant (Define Constant)Define Constant Input Parameters Using the App

  1. Click the field to the right of the input parameter name.

  2. Optionally, for numeric types, to make the parameter a complex type, select the Complex number check box.

  3. Select the input type.

    The app displays the selected type. It displays and the size options.

  4. From the list, select whether your input is a scalar, a 1 x n vector, a m x 1 vector, or a m x n matrix. By default, if you do not select a size option, the app defines inputs as scalars.

  5. Optionally, if your input is not scalar, enter sizes m and n. You can specify:

    • Fixed size, for example, 10.

    • Variable size, up to a specified limit, by using the : prefix. For example, to specify that your input can vary in size up to 10, enter :10.

    • Unbounded variable size by entering :Inf.

    You can edit the size of each dimension.

Specify a String Scalar Input Parameter

To specify that an input is a string scalar:

  1. On the Define Input Types page, click Let me enter input or global types directly.

  2. Click the field to the right of the input parameter that you want to define.

  3. Select string. Then select 1x1 scalar.

    The type is a 1-by-1 string array (string scalar) that contains a character vector.

  4. To specify the size of the character vector, click the field to the right of the string array element {1}. Select char. Then, select 1xn vector and enter the size.

  5. To make the string variable-size, click the second dimension.

    • To specify that the second dimension is unbounded, select :Inf.

    • To specify that the second dimension has an upper bound, enter the upper bound, for example 8. Then, select :8.

Specify an Enumerated Type Input Parameter

To specify that an input uses the enumerated type MyColors:

  1. Suppose that the enumeration MyColors is on the MATLAB® path.

    classdef MyColors < int32
        enumeration
            green(1),
            red(2),
        end
    end

  2. On the Define Input Types page, click Let me enter input or global types directly.

  3. In the field to the right of the input parameter, enter MyColors.

Specify a Fixed-Point Input Parameter

To specify fixed-point inputs, Fixed-Point Designer™ software must be installed.

  1. On the Define Input Types page, click Let me enter input or global types directly.

  2. Click the field to the right of the input parameter that you want to define.

  3. Select embedded.fi.

  4. Select the size. If you do not specify the size, the size defaults to 1x1.

  5. Specify the input parameter numerictype and fimath properties.

    If you do not specify a local fimath, the app uses the default fimath. See Default fimath Usage to Share Arithmetic Rules (Fixed-Point Designer).

To modify the numerictype or fimath properties, open the properties dialog box. To open the properties dialog box, click to the right of the fixed-point type definition. Optionally, click .

Specify a Structure Input Parameter

When a primary input is a structure, the app treats each field as a separate input. Therefore, you must specify properties for all fields of a primary structure input in the order that they appear in the structure definition:

  • For each field of an input structure, specify class, size, and complexity.

  • For each field that is a fixed-point class, also specify numerictype, and fimath.

Specify Structures by Type

  1. On the Define Input Types page, click Let me enter input or global types directly.

  2. Click the field to the right of the input parameter that you want to define.

  3. Select struct.

    The app displays the selected type, struct. The app displays the size options.

  4. Specify that your structure is a scalar, 1 x n vector, m x 1 vector, or m x n matrix. By default, if you do not select a size option, the app defines inputs as scalars.

  5. If your input is not scalar, enter sizes for each dimension. Click the dimension. Enter the size. Select from the size options. For example, for size 10:

    • To specify fixed size, select 10.

    • To specify variable size with an upper bound of 10, select :10.

    • To specify unbounded variable size, select :Inf.

  6. Optionally, specify properties for the structure in the generated code. See Set Structure Properties.

  7. Add fields to the structure. Specify the class, size, and complexity of the fields. See Add a Field to a Structure.

Set Structure Properties

  1. Click to the right of the structure definition. Optionally, click .

  2. In the dialog box, specify properties for the structure in the generated code.

    PropertyDescription
    C type definition name

    Name for the structure type in the generated code.

    Type definition is externally defined

    Default: No — type definition is not externally defined.

    If you select Yes to declare an externally defined structure, the app does not generate the definition of the structure type. You must provide it in a custom include file.

    Dependency: C type definition name enables this option.

    C type definition header file

    Name of the header file that contains the external definition of the structure, for example, "mystruct.h". Specify the path to the file using the Additional include directories parameter on the project settings dialog box Custom Code tab.

    By default, the generated code contains #include statements for custom header files after the standard header files. If a standard header file refers to the custom structure type, then the compilation fails. If you specify the C type definition header file, the app includes that header file exactly at the point where it is required.

    Dependency: When Type definition is externally defined is set to Yes, this option is enabled.

    Data alignment boundary

    The run-time memory alignment of structures of this type in bytes.

    If you have an Embedded Coder® license and use Code Replacement Libraries (CRLs), the CRLs provide the ability to align data objects passed into a replacement function to a specified boundary. You can take advantage of target-specific function implementations that require aligned data. By default, the structure is not aligned on any specific boundary so it is not matched by CRL functions that require alignment.

    Alignment must be either -1 or a power of 2 that is no more than 128.

    Default: 0

    Dependency: When Type definition is externally defined is set to Yes, this option is enabled.

Rename a Field in a Structure

Select the name field of the structure that you want to rename. Enter the new name.

Add a Field to a Structure

  1. To the right of the structure, click

  2. Enter the field name. Specify the class, size, and complexity of the field.

Insert a Field into a Structure

  1. Select the structure field below which you want to add another field.

  2. Right-click the structure field.

  3. Select Insert Field Below.

    The app adds the field after the field that you selected.

  4. Enter the field name. Specify the class, size, and complexity of the field.

Remove a Field from a Structure

  1. Right-click the field that you want to remove.

  2. Select Remove Field.

Specify a Cell Array Input Parameter

For code generation, cell arrays are homogeneous or heterogeneous. See Code Generation for Cell Arrays. A homogeneous cell array is represented as an array in the generated code. All elements have the same properties. A heterogeneous cell array is represented as a structure in the generated code. Elements can have different properties.

Specify a Homogeneous Cell Array

  1. On the Define Input Types page, click Let me enter input or global types directly.

  2. Click the field to the right of the input parameter that you want to define.

  3. Select cell (Homogeneous).

    The app displays the selected type, cell. The app displays the size options.

  4. From the list, select whether your input is a scalar, a 1 x n vector, a m x 1 vector, or a m x n matrix. By default, if you do not select a size option, the app defines inputs as scalars.

  5. If your input is not scalar, enter sizes for each dimension. Click the dimension. Enter the size. Select from the size options. For example, for size 10:

    • To specify fixed size, select 10.

    • To specify variable size with an upper bound of 10, select :10.

    • To specify unbounded variable size, select :Inf.

    Below the cell array variable, a colon inside curly braces {:} indicates that the cell array elements have the same properties (class, size, and complexity).

  6. To specify the class, size, and complexity of the elements in the cell array, click the field to the right of {:}.

Specify a Heterogeneous Cell Array

  1. On the Define Input Types page, click Let me enter input or global types directly.

  2. Click the field to the right of the input parameter that you want to define.

  3. Select cell (Heterogeneous).

    The app displays the selected type, cell. The app displays the size options.

  4. Specify that your structure is a scalar, 1 x n vector, m x 1 vector, or m x n matrix. By default, if you do not select a size option, the app defines inputs as scalars.

  5. Optionally, if your input is not scalar, enter sizes m and n. A heterogeneous cell array is fixed size.

    The app lists the cell array elements. It uses indexing notation to specify each element. For example, {1,2} indicates the element in row 1, column 2.

  6. Specify the class, size, and complexity for each cell array element.

  7. Optionally, add elements. See Add an Element to a Heterogeneous Cell Array

  8. Optionally, specify properties for the structure that represents the cell array in the generated code. See Set Structure Properties for a Heterogeneous Cell Array.

Set Structure Properties for a Heterogeneous Cell Array

A heterogeneous cell array is represented as a structure in the generated code. You can specify the properties for the structure that represents the cell array.

  1. Click to the right of the cell array definition. Optionally click .

  2. In the dialog box, specify properties for the structure in the generated code.

    PropertyDescription
    C type definition name

    Name for the structure type in the generated code.

    Type definition is externally defined

    Default: No — type definition is not externally defined.

    If you select Yes to declare an externally defined structure, the app does not generate the definition of the structure type. You must provide it in a custom include file.

    Dependency: C type definition name enables this option.

    C type definition header file

    Name of the header file that contains the external definition of the structure, for example, "mystruct.h". Specify the path to the file using the Additional include directories parameter on the project settings dialog box Custom Code tab.

    By default, the generated code contains #include statements for custom header files after the standard header files. If a standard header file refers to the custom structure type, then the compilation fails. If you specify the C type definition header file, the app includes that header file exactly at the point where it is required.

    Dependency: When Type definition is externally defined is set to Yes, this option is enabled.

    Data alignment boundary

    The run-time memory alignment of structures of this type in bytes.

    If you have an Embedded Coder license and use Code Replacement Libraries (CRLs), the CRLs provide the ability to align data objects passed into a replacement function to a specified boundary. You can take advantage of target-specific function implementations that require aligned data. By default, the structure is not aligned on any specific boundary so it is not matched by CRL functions that require alignment.

    Alignment must be either -1 or a power of 2 that is no more than 128.

    Default: 0

    Dependency: When Type definition is externally defined is set to Yes, this option is enabled.

Change Classification as Homogeneous or Heterogeneous

To change the classification as homogeneous or heterogeneous, right-click the variable. Select Homogeneous or Heterogeneous.

The app clears the definitions of the elements.

Change the Size of the Cell Array

  1. In the definition of the cell array, click a dimension. Specify the size.

  2. For a homogeneous cell array, specify whether the dimension is variable size and whether the dimension is bounded or unbounded. Alternatively, right-click the variable. Select Bounded (fixed-size), Bounded (variable-size), or Unbounded

  3. For a heterogeneous cell array, the app adds elements so that the cell array has the specified size and shape.

Add an Element to a Heterogeneous Cell Array

  1. In the definition of the cell array, click a dimension. Specify the size. For example, enter 1 for the first dimension and 4 for the second dimension.

    The app adds elements so that the cell array has the specified size and shape. For example for a 1x4 heterogeneous cell array, the app lists four elements: {1,1}, {1,2}, {1,3}, and {1,4}.

  2. Specify the properties of the new elements.

Was this topic helpful?