Programmatic Model Editing
You can programmatically create, edit, search, and check Simulink® models. To interact with a model programmatically, the model must be loaded. Creating or opening a model also loads the model. Use the functions listed under Create Models to create, load, or open a model. Then, use the other functions on this page to programmatically edit the model and its content. In the function input arguments, specify the object you want the function to edit as a handle, path, or filename. This target object can be a model, a component such as a subsystem or library, or a model element such as a block or signal line. You can specify target objects whose names and locations you know, or you can programmatically search for target objects that meet certain criteria. See the function documentation and Get Handles and Paths for details.
When you want to share a model with a third party without revealing
intellectual property, create a protected version of your model using the
Simulink.ModelReference.protect
(Embedded Coder)
function. See Protect Models to Conceal Contents (Embedded Coder) for details.
For information about how to programmatically run simulations, see Run Simulations Programmatically. To programmatically create and edit projects, see Create and Edit Projects Programmatically. To programmatically configure the Simulink Editor, see Programmatic Model Editor Appearance Parameters. To debug simulations from the MATLAB® Command Window, see Debug Simulations Programmatically.
Functions
Objects
ModelFinderFilter | Model Finder search filter (Since R2025a) |
Simulink.Annotation | Create and specify properties of text, image, and area annotations |
Topics
Specify Objects to Edit Programmatically
- Get Handles and Paths
Programmatically specify models, components, and model elements you want to edit. - Search Programmatically
Find models, blocks, signal lines, ports, and annotations.
Create Models
- Create, Load, Open, Save, and Close Models Programmatically
Run model file operations. - Add, Copy, Replace, and Delete Blocks Programmatically
Populate models with blocks. - Connect Blocks Programmatically
Connect blocks with signal lines. - Programmatically Specify Block Parameters and Properties
To write scripts that modify block behavior, determine the programmatic names and supported values of block parameters and properties.
Format Models
- Configure Model Layout Programmatically
Change the position and arrangement of blocks. - Group Blocks into Subsystems Programmatically
Use subsystems to organize large models. - Configure Model Element Names and Labels Programmatically
Name blocks, and label signal lines and ports. - Create and Edit Annotations Programmatically
Create and edit text, image, and area annotations programmatically. - Configure Model Style Elements Programmatically
Change model fonts and colors. - Control Masks Programmatically
Specify and edit block masks programmatically.
Share Models
- Print Models Programmatically
Use the MATLABprint
command to print Simulink models.