This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Simulink Function

Function defined with Simulink blocks

  • Library:
  • Simulink / User-Defined Functions

    SimEvents

Description

The Simulink Function block is a Subsystem block preconfigured as a starting point for graphically defining a function with Simulink® blocks. The block provides a text interface to function callers. You can call a Simulink Function block from a Function Caller block, a MATLAB Function block, or a Stateflow® Chart.

For a description of the block parameters, see the Subsystem block reference page in the Simulink documentation.

You can visualize Simulink Function calls in the Sequence Viewer. The viewer shows when calls were made with the argument and the return values. See Sequence Viewer block reference.

Function Interface

The function interface appears on the face of a Simulink Function block. Editing the block text adds and deletes Argument Inport blocks and Argument Outport blocks from the function definition. Editing also sets the Function name parameter in the Trigger block within the Simulink Function block.

For example, entering y = myfunction(u) on the face of a Simulink Function block adds one Argument Inport block (u) and one Argument Outport block (y) within the subsystem.

When calling a function using a Function Caller block, the parameter Function prototype in the Function Caller block must match exactly the function interface you specify on the Simulink Function block. This match includes the name of the function and the names of input and output arguments. For example, the Simulink Function block and the Function Caller block both use the argument names u and y.

When calling a function from a Stateflow transition or state label, you can use different argument names. For example, the Simulink Function block uses x and y arguments while the Stateflow transition uses x2 and y2 arguments to call the function.

Function-Call Subsystems Versus Simulink Function Blocks

In general, a Function-Call Subsystem block provides better signal traceability with direct signal connections than a Simulink Function block. While a Simulink Function block eliminates the need for routing input and output signal lines through the model hierarchy.

AttributeFunction-Call Subsystem blockSimulink Function block
Method of executing/invoking functionTriggered using a signal lineCalled by reference using the function name
Formal input arguments (Argument Inport blocks) and output arguments (Argument Outport blocks)NoYes
Local inputs (Inport block) and outputs (Outport block)YesYes

Ports

Input

expand all

Placing an Inport block in a subsystem block adds an external input port to the Simulink Function block. The port label matches the name of the Inport block.

Use Inport blocks to get signals from the local environment.

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

An Argument Inport block in a subsystem block provides an input port corresponding to an input argument. A port is not displayed on the subsystem block.

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

Output

expand all

Placing an Outport block in a subsystem block adds an output port from the block. The port label on the subsystem block is the name of the Outport block.

Use Outport blocks to send signals to the local environment.

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

An Argument Outport block in a subsystem block provides an output port corresponding to an out put argument. A port is not displayed on the subsystem block.

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

Block Characteristics

Data Types

Boolean[a] | bus[a] | double[a] | enumerated[a] | fixed point[a] | integer[a] | single[a] | string[a]

Direct Feedthrough

no

Multidimensional Signals

limited[a]

Variable-Size Signals

no

Zero-Crossing Detection

no

[a] Actual data type or capability support depends on block implementation.

Extended Capabilities

Introduced in R2014b