Define Input Parameter by Example by Using the App

Define an Input Parameter by Example

  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 Define by Example.

  4. In the field to the right of the parameter, enter a MATLAB® expression. The variable has the class, size, and complexity of the value of the expression.

Specify Input Parameters by Example

This example shows how to specify a 1-by-4 vector of unsigned 16-bit integers.

  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 Define by Example.

  4. In the field to the right of the parameter, enter:

    zeros(1,4,'uint16')

    The input type is uint16(1x4).

  5. Optionally, after you specify the input type, you can specify that the input is variable size. For example, select the second dimension.

  6. To specify that the second dimension is variable size with an upper bound of 4, select :4. Alternatively, to specify that the second dimension is unbounded, select :Inf.

Alternatively, you can specify that the input is variable size by using the coder.newtype function. Enter the following MATLAB expression:

coder.newtype('uint16',[1 4],[0 1])

    Note:   To specify that an input is a double-precision scalar, enter 0.

Specify a Structure Type Input Parameter by Example

This example shows how to specify a structure with two fields a and b. The input type of a is scalar double. The input type of b is scalar char.

  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 Define by Example.

  4. In the field to the right of the parameter, enter:

    struct('a', 1, 'b', 'x')
    

    The type of the input parameter is struct(1x1). The type of field a is double(1x1). The type of field b is char(1x1)

  5. For an array of structures, to specify the size of each dimension, click the dimension and specify the size. For example, enter 4 for the first dimension.

  6. To specify that the second dimension is variable size with an upper bound of 4, select :4. Alternatively, to specify that the second dimension is unbounded select :Inf.

Alternatively, specify the size of the array of structures in the struct function call. For example, struct('a', { 1 2}, 'b', {'x', 'y'}) specifies a 1x2 array of structures with fields a and b. The type of field a is double(1x1). The type of field b is char(1x1).

To modify the type definition, see Specify a Structure Input Parameter.

Specify a Cell Array Type Input Parameter by Example

This example shows how to specify a cell array input by example. When you define a cell array by example, the app determines whether the cell array is homogeneous or heterogeneous. See Code Generation for Cell Arrays. If you want to control whether the cell array is homogeneous or heterogeneous, specify the cell array by type. See Specify a Cell Array Input Parameter.

  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 Define by Example.

  4. In the field to the right of the parameter, enter an example cell array.

    • If all cell array elements have the same properties, the cell array is homogeneous. For example, enter:

      {1 2 3}
      
      The input is a 1x3 cell array. The type of each element is double(1x1).

      The colon inside curly braces{:} indicates that all elements have the same properties.

    • If elements of the cell array have different classes, the cell array is heterogeneous. For example, enter:

      {'a', 1}
      The input is a 1x2 cell array. For a heterogeneous cell array, the app lists each element. The type of the first element is char(1x1). The type of the second element is double(1x1).

    • For some example cell arrays. the classification as homogeneous or heterogeneous is ambiguous. For these cell arrays, the app uses heuristics to determine whether the cell array is homogeneous or heterogeneous. For example, for the example cell array, enter:

      {1 [2 3]}
      The elements have the same class, but different sizes. The app determines that the input is a 1x2 heterogeneous cell array. The type of the first element is double(1x1). The type of the second element is double(1x2).

      However, the example cell array, {1 [2 3]}, can also be a homogeneous cell array whose elements are 1x:2 double. If you want this cell array to be homogeneous, do one of the following:

      • Specify the cell array input by type. Specify that the input is a homogeneous cell array. Specify that the elements are 1x:2 double. See Specify a Cell Array Input Parameter.

      • Right-click the variable. Select Homogeneous. Specify that the elements are 1x:2 double.

      If you use coder.typeof to specify that the example cell array is variable size, the app makes the cell array homogeneous. For example, for the example input, enter:

      coder.typeof({1 [2 3]}, [1 3], [0 1])
      The app determines that the input is a 1x:3 homogeneous cell array whose elements are 1x:2 double.

To modify the type definition, see Specify a Cell Array Input Parameter.

Specify an Enumerated Type Input Parameter by Example

This example shows how to specify that an input uses the enumerated type MyColors.

Suppose that MyColors.m is on the MATLAB path.

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

To specify that an input has the enumerated type MyColors:

  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 Define by Example.

  4. In the field to the right of the parameter, enter the following MATLAB expression:

    MyColors.red

Specify a Fixed-Point Input Parameter by Example

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

This example shows how to specify a signed fixed-point type with a word length of eight bits, and a fraction length of three bits.

  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 Define by Example.

  4. In the field to the right of the parameter, enter:

    fi(10, 1, 8, 3) 

    The app sets the type of input u to fi(1x1). By default, if you do not specify a local fimath, the app uses the default fimath. See fimath for Sharing Arithmetic Rules.

    Optionally, modify the fixed-point properties or the size of the input. See Specify a Fixed-Point Input Parameter by Type and Define or Edit Input Parameter Type by Using the App.

Was this topic helpful?