Documentation

MATLAB Function Block Editor

Customizing the MATLAB Function Block Editor

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 (MATLAB).

MATLAB Function Block Editor Tools

Use the following tools to work with the MATLAB Function block:

Tool ButtonDescription

Edit Data

Opens the Ports and Data Manager dialog to add or modify arguments for the current MATLAB Function block. To learn more, 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.

Editing and Debugging MATLAB Function Block Code

Manual Indenting

To indent a block of code manually:

  1. Highlight the text that you would like to indent.

  2. Select one of the Indent tools on the Editor tab:

    ToolDescription
    Applies smart indenting to selected text.
    Move selected text right one indent level.
    Move selected text left one indent level.

Opening a Selection

You can open a local function, function, file, or variable from within a file in the MATLAB Function Block Editor.

To open a selection:

  1. Position the cursor in the name of the item you would like to open.

  2. Right-click 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 (MATLAB).

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.

Evaluating a Selection

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:

  1. Highlight the variable or equation that you would like to evaluate.

  2. Hold the mouse over the highlighted text and then right-click 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.

Setting Data Scope

To set the data scope of a MATLAB Function block input parameter:

  1. Highlight the input parameter that you would like to modify.

  2. Hold the mouse over the highlighted text and then right-click and select Data Scope for <selection> from the context menu.

  3. 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.

Related Examples

More About

Was this topic helpful?