Main Content

Function Caller

Call Simulink or exported Stateflow function

  • Library:
  • Simulink / User-Defined Functions

  • Function Caller block

Description

A Function Caller block calls and executes a function defined with a Simulink Function block or an exported Stateflow® function. Using Function Caller blocks, you can call a function from anywhere in a model or chart hierarchy.

You can select a Simulink Function or Function Caller block to highlight related blocks. If one or more of the related blocks are in a subsystem or referenced model, the related blocks and the Subsystem block or Model block that contains the related blocks are also highlighted.

To show a related block in an open diagram or new tab, pause on the ellipsis that appears after you select a Simulink Function or Function Caller block. Then, select Related Blocks Related Blocks button from the action bar. When multiple blocks correspond to the selected block, a list of related blocks opens. You can filter the list by entering a search term in the text box. After you select a related block from the list, window focus goes to the open diagram or new tab that shows the related block.

Ports

Input

expand all

Input signal for an input argument that is sent to the function.

The function prototype determines the number and name of input ports that appear on the Function Caller block. Connect signal lines to the input ports to send data to a function through the function input arguments.

For example, y = myfunction(u) creates one input port (u) on the Function Caller block.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point | enumerated | bus

Output

expand all

Output signal for an output argument that the function returns.

The function prototype determines the number and name of output ports that appear on the Function Caller block. Connect signal or message lines to the output ports to receive data from a function through the function output arguments. The Function Caller block outputs messages when you select the Execute function call asynchronously check box.

For example, y = myfunction(u) creates one output port (y) on the Function Caller block.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point | enumerated | bus

Parameters

expand all

Specify the function interface between a Function Caller block and a Simulink® function. A Simulink function can be a Simulink Function block, an exported Stateflow graphical function, or an exported Stateflow MATLAB® function. For a call to a Simulink Function block:

  • Function call argument names must match the function arguments.

  • Function names, input arguments, and output arguments must be valid MATLAB identifiers.

Programmatic Use

Block Parameter: FunctionPrototype
Type: character vector
Values: 'y=f(u)' | '<function prototype>'
Default: 'y=f(u)'

Specify a comma-separated list of MATLAB expressions that combine data type, dimensions, and complexity (real or imaginary) for each input argument. For examples, see Argument Specification for Simulink Function Blocks.

This specification must match the Simulink Function block data type specified with the Data type parameter of the Argument Inport block.

Programmatic Use

Block Parameter: InputArgumentSpecifications
Type: character vector
Values: '' | '<MATLAB expression>'
Default: ''

Specify a comma-separated list of MATLAB expressions that combine data type, dimensions, and complexity (real or imaginary) for each output argument. For examples, see Argument Specification for Simulink Function Blocks.

This specification must match the Simulink Function block data type specified with the Data type parameter of the Argument Outport Block.

Programmatic Use

Block Parameter: OutputArgumentSpecifications
Type: character vector
Values: '' | '<MATLAB expression>'
Default: ''

Specify the interval between times that the Function Caller block calls the specified Simulink function.

By default, the block inherits its sample time based on the context of the block in the model.

To set a different sample time, enter a value using a sample time format from the table in Specify Sample Time.

If the Function Caller block has any inputs, it is a nonsource block, and you must set the sample time to -1.

Programmatic Use

Block Parameter: SampleTime
Type: character vector
Values: '-1' | sample time
Default: '-1'

Specify whether to execute function calls asynchronously for the Simulink Function block associated with this Function Caller block.

  • Select this check box to model asynchronous execution where the caller (client) makes a request to call the function (server). The function is executed based on the ordering defined in the Schedule Editor and then returns the output arguments to the caller. The block outputs these arguments using a message output port.

    • If there is one function output argument, the output argument becomes the message payload.

    • If there is more than one function output argument, the Function Caller block bundles the output arguments as a structure that becomes the message payload.

    Connect the message output port to a Message Triggered Subsystem in immediate mode. The Message Triggered Subsystem acts as a callback for the function.

  • Clear this check box to model synchronous execution where the caller calls the function and the function runs immediately then returns the output arguments to the caller.

Programmatic Use

Block Parameter: AsynchronousCaller
Type: character vector
Values: 'on' | 'off'
Default: 'off'

Block Characteristics

Data Types

Boolean | bus | double | enumerated | fixed point | integer | single

Direct Feedthrough

yes

Multidimensional Signals

yes

Variable-Size Signals

no

Zero-Crossing Detection

no

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.

Version History

Introduced in R2014b

expand all