MATLAB Function Block Editor
Create, edit, and debug MATLAB code in MATLAB Function blocks
Description
The MATLAB Function Block Editor allows you to view, edit, and create the MATLAB® functions for a MATLAB Function block. When you update the MATLAB code, Simulink® updates the MATLAB Function block with input and output ports that match the input and output arguments in the MATLAB function. The MATLAB Function Block Editor opens in the Simulink Editor.
Open the MATLAB Function Block Editor
Double-click a MATLAB Function block.
Select a MATLAB Function block and, in the Function tab, click Open in Simulink.
Examples
Related Examples
Parameters
PrepareEdit Data
— Opens the Symbols pane and Property Inspector
button
Opens the Symbols pane and the Property Inspector. Click the button to define function variables and edit properties.
Go To
— Goes to specified code
button
Goes to specified code, including functions and line numbers.
Find
— Finds and replaces code in function
button
Finds specified text written in the MATLAB Function Block Editor. You can also use the Ctrl+F keyboard shortcut. If you want to find and replace code, use the Ctrl+H keyboard shortcut. This parameter has the same functionality as the MATLAB Editor. For more information, see Find and Replace Text in Files and Go to Location.
Refactor
— Converts selected code to a function
button
Converts selected code to a function. Use this feature on code that is not already contained in a function. You can create a separate file for the function code or you can convert code into a local function.
To convert code and save it in a separate m-file, select the code and click Refactor > Convert to Function. The code saves as a m-file and the MATLAB Function Block Editor calls the code by the name you specify. To run the model without error, the m-file must be on the path.
To convert code into a local function, select the code and click Refactor > Convert to Local Function. The MATLAB Function Block Editor creates a local function at the bottom of the code and replaces the selected code with a function call to the local function.
Comment
— Comments out code
button
Comments out code. Select the lines you want to comment and click the Comment button
. The button adds one
%
to the
selected lines each time you press it. You can also select the code and use the
Ctrl+R keyboard shortcut.
Uncomment
— Removes comments from code
button
Removes comments from code. Select the lines you want to uncomment and click the
Uncomment button . The button removes one
%
from the
selected lines each time you press it. You can also select the code and use the
Ctrl+T keyboard shortcut.
Wrap Comments
— Wraps comments
button
Wraps comments. Select the lines you want to comment and click the Wrap comments
button .
The MATLAB Function Block Editor does not wrap comments with:
Code section titles (comments that begin with
%%
).Long contiguous text, such as URLs.
Bulleted list items (text that begins with
*
or#
) onto the preceding line.
Smart Indent
— Formats code with smart indenting
button
Formats code with smart Indenting. Smart indenting automatically formats code to
improve code readability, such as when you use functions or logical statements. To
manually deploy smart indenting, select the lines of code and click the Smart Indent
button . By default, the MATLAB Function Block
Editor automatically uses smart indenting. For more information, see Edit and Format Code.
Increase Indent
— Increases the code indent
button
Increases the code indent by one tab indent. To increase the indent, select the
lines of code and click the Increase Indent button .
Decrease Indent
— Decreases the code indent
button
Decreases the code indent by one tab indent if the code is indented. To decrease the
indent, select the lines code and click the Decrease Indent button
.
Specify fixed-point data
— Builds fi object constructors
button
Builds fi object constructors with a user interface. To open the interface, click
the Specify fixed-point data button . Click the arrow next to the icon to select additional
fi constructors. For more information, see Building fimath Object Constructors in a GUI (Fixed-Point Designer).
This features requires a Fixed-Point Designer™ license.
Update Model
— Updates the model and checks for errors
button
Updates the model and checks for errors. Expand the menu under Update Model to select from two options.
Update Model: Compiles the model and checks for static errors.
Refresh blocks: Updates the model blocks to reflect changes made.
You can also use the Ctrl+Shift+D keyboard shortcut to update the model. For more information, see Update Diagram and Run Simulation and Simulation Phases in Dynamic Systems.
Stop Time
— Specifies the simulation stop time
10
(default) | scalar
Specifies the simulation stop time.
Simulation Mode
— Changes the simulation mode
menu item
Changes the simulation mode. You can select from Normal, Accelerator or Rapid Accelerator. For more information, see Choosing a Simulation Mode.
Fast Restart
— Enables fast restart
"off"
(default) | "on"
Enables fast restart for model simulation. Fast restart can improve performance by preventing compiling. For more information, see Get Started with Fast Restart.
Step Back
— Steps back in simulation
button
Steps back in simulation. You must configure this option first with the Simulation Stepping Options. If you have not configured these options, the button opens the Simulation Stepping Options window. For more information, see Simulation Stepping Options.
Run
— Runs the simulation
button
Runs the simulation. You can run a single simulation, or run multiple simulations by creating design studies with Multiple Simulations and selecting Run All from the drop down. Adjust the time pacing by selecting Simulation Pacing from the drop down.
Step Forward
— Steps through the simulation at each time step
button
Steps through the simulation at each time step. For more information, see Step Through a Simulation.
Stop
— Stops the simulation
button
Stops the simulation.
Step over
— Steps over the breakpoint during debugging
button
Steps over the breakpoint during debugging in the MATLAB Function block. When you press the button, the debugger steps past function calls and does not enter called functions for line-by-line execution. You can use this button only after simulation stops at a breakpoint.
Step In
— Goes to next line of code during debugging
button
Goes to next line of code during debugging in the MATLAB Function block. If the line calls a local function, step into the first line of the local function. You can use this button only after simulation stops at a breakpoint.
Step out
— Exits line-by-line function execution during debugging
button
Exits line-by-line function execution during debugging of the current function or local function. If in a local function, the debugger continues to the line following the call to this local function. You can use this button only after simulation stops at a breakpoint.
Function Report
— Opens a report
button
Opens a report that contains information about the MATLAB Function. You can use this report to find information about variables and expressions in the code. For more information, see MATLAB Function Reports.