Main Content

Argument Specification for Simulink Function Blocks

A Simulink Function block is considered to be out of scope of a Function Caller block when the two blocks are in separate models referenced by a common parent model.

  • When a Simulink Function block is within the scope of a Function Caller block, the Function Caller block can inherit the input and output argument specifications. You do not have to specify parameters of the Function Caller block.

  • When a Simulink Function block is outside the scope of the Function Caller block, you must specify the input and output argument specifications of a Function Caller block.

Example Argument Specifications for Data Types

This table lists possible input and output argument specifications.

Simulink Function Block Data TypeFunction Caller Block ExpressionDescription
doubledouble(1.0)Double-precision scalar.
doubledouble(ones(12,1))Double-precision column vector of length 12.
singlesingle(1.0)Single-precision scalar.
int8, int16, int32int8(1), int16(1), int32(1)Integer scalars.
 int32([1 1 1])Integer row vector of length 3.
 int32(1+1i)Complex scalar whose real and imaginary parts are 32-bit integers.
uint8, int16, int32uint8(1), uint16(1), uint32(1)Unsigned integer scalars.
booleanboolean(true),boolean(false)Boolean, initialized to true (1) or false (0).

fixdt(1,16)

fixdt (signed, word_length)

fi(0,1,16)

fi (value, signed, word_length)

16-bit fixed-point signed scalar with binary point set to zero.

Fixed-point numbers can have a word size up to 65,535 bits.

fixdt(1,16,4)fi(0,1,16,4)16-bit fixed-point signed scalar with binary point set to 4.
fixdt(1,16,2^0,0)fi(0,1,16,2^0,0)16-bit fixed-point signed scalar with slope set to 2^0 and bias set to 0.
Bus: <object name>bus object nameSimulink.Bus object
Enum: <class name>enumerated valueEnumerated type set to an enumerated value.
<alias name>parameter object nameSimulink.Parameter object with the DataType parameter set to a Simulink.AliasType object and the Value parameter set to a value.

Input Argument Specification for Enumerated Data Type

Create an enumerated data type for the three primary colors, and then specify the Input argument specifications parameter for a Function Caller block. The Function Caller block calls a Simulink Function block that accepts a signal with the enumerated type as input.

  1. Create a MATLAB® file for saving the data type definition. On the MATLAB toolstrip, select New > Class.

  2. In the MATLAB editor, define the elements of an enumerated data type. The class BasicColors is a subclass of the class Simulink.IntEnumType.

    classdef BasicColors < Simulink.IntEnumType
      enumeration
        Red(0)
        Yellow(1)
        Blue(2) 
      end
    end 

  3. Save the class definition in a file named BasicColors.m.

  4. For the Function Caller block dialog box, set the Input argument specifications to BasicColors(0).

  5. For the dialog box of an Argument Inport block within the Simulink Function block, set the Data type parameter to Enum: BasicColors.

Input Argument Specification for an Alias Data Type

Create an alias name for the data type single, and then specify the Input argument specification parameter for a Function Caller block. The Simulink Function block called by the Function Caller block also uses the alias name to define the input data type.

  1. Create a Simulink® alias data type object myAlias.

    myAlias = Simulink.AliasType;
  2. Assign a data type.

    myAlias.BaseType = 'single';

  3. Create a Simulink parameter object myAlias_parameter and assign the alias name to the DataType parameter.

    myAlias_parameter = Simulink.Parameter;
    myAlias_parameter.DataType = 'myAlias';
    myAlias_parameter.Value = 1;
  4. For the Function Caller block dialog box, set the Input argument specification parameter to myAlias_parameter.

  5. For the dialog box of an Argument Inport block dialog box within the Simulink Function block, set the Data type parameter to myAlias.

Input Argument Specification for Unbounded Variable-Size Signals

Since R2023b

The Function Caller block only accepts Simulink.Signal objects that represent unbounded variable-size signals. For more information, see Unbounded Variable-Size Signals.

The following steps show how to specify an unbounded variable-size signal as input argument for a Function Caller block and how to configure the related Simulink Function block.

  1. Create a Simulink.Signal object mySig that represents the input signal.

    mySig = Simulink.Signal;
    mySig.Dimensions = [Inf 2];
    mySig.DimensionsMode = 'Variable';

    Now, create a Simulink.Signal object mySigOut that represents the output signal.

    mySigOut = Simulink.Signal;
    mySigOut.Dimensions = [Inf Inf];
    mySigOut.DimensionsMode = 'Variable';

  2. For the Function Caller block dialog box, set the Input argument specifications and the Output argument specifications parameters to mySig and mySigOut, respectively.

  3. Configure the Inport block connected to the Function Caller block input argument port so that the block accepts unbounded variable-size signals. In the Inport block dialog box:

    • Set the Signal Attributes > Variable-size Signals to Yes.

    • Specify a discrete sample time in the Execution > Sample time field.

  4. For the Argument Inport block within the Simulink Function block that calls the function defined inside the Function Caller block, set the Signal Attributes > Port dimensions parameter to match the dimensions of mySig, which are [Inf 2].

    Similarly, in the Argument Outport block, set the Signal Attributes > Port dimensions parameter to match the dimensions of mySigOut, which are [Inf Inf]. To check whether the blocks you want to use within the Simulink Function block support unbounded variable-size signals, refer to the list of blocks in Supported Blocks and Features for Simulation.

See Also

Blocks

Objects

Related Topics