Simulink Function
Graphically define a function with Simulink blocks
Libraries:
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. See Call a Simulink Function from a Model.
For a description of the block parameters, see Subsystem.
You can visualize Simulink Function calls in the Sequence Viewer. The viewer shows when calls were made with the argument and the return values.
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 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.
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, this
Simulink Function block and 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, this 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, whereas a Simulink Function block eliminates the need for routing input and output signal lines through the model hierarchy.
Attribute | Function-Call Subsystem block | Simulink Function block |
---|---|---|
Method of executing/invoking function | Triggered using a signal line | Called by reference using the function name |
Formal input arguments (Argument Inport blocks) and output arguments (Argument Outport blocks) | No | Yes |
Local inputs (Inport block) and outputs (Outport block) | Yes | Yes |
Examples
Ports
Input
Output
Parameters
Block Characteristics
Extended Capabilities
Version History
Introduced in R2014bSee Also
Blocks
- Argument Inport | Argument Outport | Trigger | Function Caller | MATLAB Function | Chart (Stateflow) | Subsystem | Function-Call Subsystem | Inport | Outport