Use the toolbar icons to customize the appearance of the MATLAB Function Block Editor in the same manner as the MATLAB^{®} editor. See Basic Settings.
Use the following tools to work with the MATLAB Function block:
Tool Button  Description 

Edit Data  Opens the Ports and Data Manager dialog to add or modify arguments for the current MATLAB Function block (see Ports and Data Manager). 
View Report  Opens the MATLAB Function report for the MATLAB Function block. For more information, see MATLAB Function Reports. 
Simulation Target  Opens the Simulation Target pane in the Configuration Parameters dialog to include custom code. 
Go To Diagram  Displays the MATLAB function in its native diagram without closing the editor. 
See Defining Inputs and Outputs for an example of defining an input argument for a MATLAB Function block.
To indent a block of code manually:
Highlight the text that you would like to indent.
Select one of the Indent tools on the Editor tab:
Tool  Description 

Applies smart indenting to selected text.  
Move selected text right one indent level.  
Move selected text left one indent level. 
You can open a local function, function, file, or variable from within a file in the MATLAB Function Block Editor.
To open a selection:
Position the cursor in the name of the item you would like to open.
Rightclick and select Open <selection> from the context menu.
The Editor chooses the appropriate tool to open the selection. For more information, refer to Manage Files and Folders.
Note: If you open a MATLAB Function block input or output parameter, the Ports and Data Manager opens with the selected parameter highlighted. You can use the Ports and Data Manager to modify parameter attributes. For more information, refer to Ports and Data Manager. 
You can use the Evaluate a Selection menu option to report the value for a MATLAB function variable or equation in the MATLAB window during simulation.
To evaluate a selection:
Highlight the variable or equation that you would like to evaluate.
Hold the mouse over the highlighted text and then rightclick and select Evaluate Selection from the context menu. (Alternatively, select Evaluate Selection from the Text menu).
When you reach a breakpoint, the MATLAB command Window displays the value of the variable or equation at the Command Line Debugger prompt.
debug>> stdev 1.1180 debug>>
Note: You cannot evaluate a selection while MATLAB is busy, for example, running a MATLAB file. 
To set the data scope of a MATLAB Function block input parameter:
Highlight the input parameter that you would like to modify.
Hold the mouse over the highlighted text and then rightclick and select Data Scope for <selection> from the context menu.
Select:
Input if your input data is provided by the Simulink^{®} model via an input port to the MATLAB Function block.
Parameter if your input is a variable of the same name in the MATLAB or model workspace or in the workspace of a masked subsystem containing this block.
For more information, refer to Setting General Properties.
The Ports and Data Manager provides a convenient method for defining objects and modifying their properties in a MATLAB Function block.
The Ports and Data Manager provides the same data definition capabilities for individual MATLAB Function blocks as the Model Explorer provides across the model hierarchy (see Model Explorer Overview).
The Ports and Data Manager dialog box allows you to add and define data arguments, input triggers, and function call outputs for MATLAB Function blocks. Using this dialog, you can also modify properties for the MATLAB Function block and the objects it contains.
The dialog box consists of two panes:
The Contents (left) pane lists the objects that have been defined for the MATLAB Function block.
The Dialog (right) pane displays fields for modifying the properties of the selected object.
Properties vary according to the scope and type of the object. Therefore, the Ports and Data Manager properties dialogs are dynamic, displaying only the property fields that are relevant for the object you add or modify.
When you first open the dialog box, it displays the properties of the MATLAB Function block.
To open the Ports and Data Manager from the MATLAB Function Block Editor, select Edit Data on the Editor tab. The Ports and Data Manager appears for the MATLAB Function block that is open and has focus.
The following tools are specific to the Ports and Data Manager:
Tool Button  Description 

Go to Block Editor  Displays the MATLAB function in the MATLAB Function Block Editor. 
Show Block Dialog  Displays the default MATLAB function properties (see MATLAB Function Block Properties). Use this button to return to the settings used by the block after viewing data associated with the block arguments. 
This section describes each property of a MATLAB Function block.
Name. Name of the MATLAB Function block, following the same naming conventions as for Simulink blocks (see Manipulate Block Names).
Update method. Method for activating the MATLAB Function block. You can choose from the following update methods:
Update Method  Description 

Inherited (default)  Input from the Simulink model activates the MATLAB
Function block. If you define an input trigger, the MATLAB Function block executes in response to a Simulink signal or functioncall event on the trigger port. If you do not define an input trigger, the MATLAB Function block implicitly inherits triggers from the model. These implicit events are the sample times (discrete or continuous) of the signals that provide inputs to the chart. If you define data inputs, the MATLAB Function block samples at the rate of the fastest data input. If you do not define data inputs, the MATLAB Function block samples as defined by its parent subsystem's execution behavior. 
Discrete  The MATLAB Function block is sampled at the rate you specify as the block's Sample Time property. An implicit event is generated at regular time intervals corresponding to the specified rate. The sample time is in the same units as the Simulink simulation time. Note that other blocks in the model can have different sample times. 
Continuous  The Simulink software wakes up (samples) the MATLAB Function block at each step in the simulation, as well as at intermediate time points that can be requested by the solver. This method is consistent with the continuous method. 
Saturate on integer overflow. Option that determines how the MATLAB Function block handles overflow conditions during integer operations:
Setting  Action When Overflow Occurs 

Enabled (default)  Saturates an integer by setting it to the maximum positive or negative value allowed by the word size. Matches MATLAB behavior. 
Disabled  In simulation mode, generates a runtime error. For Simulink Coder™ code generation, the behavior depends on your C language compiler. 
Note: The Saturate on integer overflow option is relevant only for integer arithmetic. It has no effect on fixedpoint or doubleprecision arithmetic. 
When you enable Saturate on integer overflow, MATLAB adds additional checks during simulation to detect integer overflow or underflow. Therefore, it is more efficient to disable this option if you are sure that integer overflow and underflow will not occur in your MATLAB Function block code.
Note that the code generated by Simulink Coder does not check for integer overflow or underflow and, therefore, may produce unpredictable results when Saturate on integer overflow is disabled. In this situation, it is recommended that you simulate first to test for overflow and underflow before generating code.
Lock Editor. Option for locking the MATLAB Function Block Editor. When enabled, this option prevents users from making changes to the MATLAB Function block.
Treat these inherited Simulink signal types as fi objects
Setting that determines whether to treat inherited fixedpoint
and integer signals as FixedPoint Designer™ fi
objects (Ways to Construct fi Objects).
When you select Fixedpoint
,
the MATLAB Function block treats all fixedpoint inputs
as FixedPoint Designer fi
objects.
When you select Fixedpoint & Integer
,
the MATLAB Function block treats all fixedpoint and
integer inputs as FixedPoint Designer fi
objects.
MATLAB Function block fimath. Setting that defines fimath
properties
for the MATLAB Function block. The block associates
the fimath
properties you specify with the following
objects:
All fixedpoint and integer input signals to the MATLAB
Function block that you choose to treat as fi
objects.
All fi
and fimath
objects
constructed in the MATLAB Function block.
You can select one of the following options for the MATLAB Function block fimath.
Setting  Description 

Same as MATLAB  When you select this option, the block uses the same 
Specify other  When you select this option, you can specify your own
For more information on 
Description. Description of the MATLAB Function block.
Document link. Link to documentation for the MATLAB Function block. To document a MATLAB Function block, set the Document link property to a Web URL address or MATLAB expression that displays documentation in a suitable format (for example, an HTML file or text in the MATLAB Command Window). The MATLAB Function block evaluates the expression when you click the blue Document link text.
You can define data arguments for MATLAB Function blocks using the following methods:
Method  For Defining  Reference 

Define data directly in the MATLAB Function block code  Input and output data  See Defining Inputs and Outputs. 
Use the Ports and Data Manager  Input, output, and parameter data in the MATLAB Function block that is open and has focus  See Defining Data in the Ports and Data Manager. 
Use the Model Explorer  Input, output, and parameter data in MATLAB Function blocks at all levels of the model hierarchy  See Model Explorer Overview 
Defining Data in the Ports and Data Manager. To add a data argument, in the Ports and Data Manager, select Add > Data and modify the data properties.
Setting General Properties. You can set the following properties in the General tab:
Property  Description  

Name  Name of the data argument, following the same naming conventions used in MATLAB.  
Scope  Where data resides in memory, relative to its parent. Scope determines the range of functionality of the data argument. You can set scope to one of the following values:
For more information, see Defining Inputs and Outputs and Add Parameter Arguments.  
Port  Index of the port associated with the data argument. This property applies only to input and output data.  
Tunable  Indicates whether the parameter used as the source of this data item is tunable (see Tunable Parameters). This property applies only to parameter data. Clear this option if the parameter must be a constant expression, such as for MATLAB toolbox functions supported for code generation (see Functions and Objects Supported for C and C++ Code Generation — Alphabetical List).  
Data must resolve to Simulink signal object  Specifies that the data argument must resolve to a Simulink signal object. This property applies only to output data. See Symbol Resolution for more information.  
Size  Size of the data argument. Size can be a scalar value or a MATLAB vector of values. Size defaults to –1, which means that it is inherited, as described in Inheriting Argument Sizes from Simulink. This property does not apply to Data Store Memory data. For more details, see Size Function Arguments.  
Variable Size  Indicates whether the size of this data item is variable. This property does not apply to Data Store Memory data.  
Complexity  Indicates real or complex data arguments. You can set complexity
to one of the following values:
 
Type  Type of data object. You can specify the data type by:
 
Unit (e.g., m, m/s^2, N*m)  Specify physical units for input and output data. By default, the property is set to inherit the unit from the Simulink signal on the corresponding input or output port. See Units in MATLAB Function Blocks.  
Limit range  Specify the range of acceptable values for input or output data. The MATLAB Function block uses this range to validate the input or output as it enters or leaves the block. You can enter an expression or parameter that evaluates to a numeric scalar value.

Setting Description Properties. You can set the following properties on the Description tab:
Property  Description 

Save final value to base workspace  The MATLAB Function block assigns the value of the data argument to a variable of the same name in the MATLAB base workspace at the end of simulation. 
Description  Description of the data argument. 
Document link  Link to documentation for the data argument. You can enter a Web URL address or a MATLAB command that displays documentation in a suitable format, such as an HTML file or text in the MATLAB Command Window. When you click the blue text, Document link, displayed at the bottom of the Data properties dialog, the MATLAB Function block evaluates the link and displays the documentation. 
An input trigger is an event on the input port that causes the MATLAB Function block to execute. See Create a Triggered Subsystem.
You can define the following types of triggers in MATLAB Function blocks:
Rising
Falling
Either (rising or falling)
Function call
For a description of each trigger type, see Setting Input Trigger Properties.
Use the Ports and Data Manager to add input triggers to a MATLAB Function block that is open and has focus. To add an input trigger and modify its properties, follow these steps:
In the Ports and Data Manager, select Add > Input Trigger.
The Ports and Data Manager adds a default definition of the new input trigger to the MATLAB Function block and displays the Trigger properties dialog.
Modify trigger properties.
Return to the MATLAB Function block properties at any time by selecting Tools > Block Dialog.
The Trigger Properties Dialog. The Trigger properties dialog in the Ports and Data Manager allows you to set and modify the properties of input triggers in MATLAB Function blocks.
To open the Trigger properties dialog, select an input trigger in the Contents pane.
Setting Input Trigger Properties. You can set the following properties in the Trigger properties dialog:
Property  Description 

Name  Name of the input trigger, following the same naming conventions used in MATLAB. 
Port  Index of the port associated with the input trigger. The default
value is 1 . 
Trigger  Type of event that triggers execution of the MATLAB
Function block. You can select one of the following types
of triggers:

Description  Description of the input trigger. 
Document link  Link to documentation for the input trigger. You can enter a Web URL address or a MATLAB command that displays documentation in a suitable format, such as an HTML file or text in the MATLAB Command Window. When you click the blue text that reads Document link displayed at the bottom of the Trigger properties dialog, the MATLAB Function block evaluates the link and displays the documentation. 
A function call output is an event on the output port of a MATLAB Function block that causes a FunctionCall Subsystem block in the Simulink model to execute. Another block can invoke a functioncall subsystem directly during a simulation. See Create a FunctionCall Subsystem.
Use the Ports and Data Manager to add and modify function call outputs to a MATLAB Function block that is open and has focus. To add a function call output and modify its properties, follow these steps:
In the Ports and Data Manager, select Add > Function Call Output.
The Ports and Data Manager adds a default definition of the new function call output to the MATLAB Function block and displays the Function Call properties dialog.
Modify function call output properties.
Return to the MATLAB Function block properties at any time by selecting Tools > Block Dialog.
Considerations when Supplying Output to the FunctionCall Subsystem. If a MATLAB Function block triggers a functioncall subsystem, and supplies an output signal to the same functioncall subsystem, the signal to the functioncall subsystem can effectively be delayed by one time step compared to the function call. At the moment of the function call, the functioncall subsystem sees the previous MATLAB Function block outport value even if the output data has been updated within the block MATLAB code.
The Function Call Properties Dialog. The Function Call properties dialog in the Ports and Data Manager allows you to edit the properties of function call outputs in MATLAB Function blocks.
To open the Function Call properties dialog, select a function call output in the Contents pane.
Setting Function Call Output Properties. You can set the following properties in the Function Call properties dialog:
Property  Description 

Name  Name of the function call output, following the same naming conventions used in MATLAB. 
Port  Index of the port associated with the function call output. Function call output ports are numbered sequentially after input and output ports. 
Description  Description of the function call output. 
Document link  Link to documentation for the function call output. You can enter a Web URL address or a MATLAB command that displays documentation in a suitable format, such as an HTML file or text in the MATLAB Command Window. When you click Document link displayed at the bottom of the Function Call properties dialog, the MATLAB Function block evaluates the link and displays the documentation. 