Main Content

Programmatic Model Editing

Use APIs to perform modeling basics such as adding, configuring, and connecting blocks

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

expand all

getSimulinkBlockHandleGet block handle from block path
getfullnameGet path that identifies block or line
get_paramGet parameter names and values
gcsGet path name of current system
gcbGet path name of current block
gcbhGet handle of current block
gcbpGet Simulink.BlockPath object for current block
bdrootTop-level model of current system
getCurrentAnnotationGet current annotation object
getCallbackAnnotationGet annotation executing callback

Find Model Elements

find_systemFind models, blocks, lines, ports, and annotations
Simulink.findBlocksFind blocks in Simulink models
Simulink.findBlocksOfTypeFind specified type of block in Simulink models
Simulink.FindOptionsSpecify options for finding blocks in models and subsystems
hilite_systemHighlight block, signal line, port, or annotation

Find Models

find_systemFind models, blocks, lines, ports, and annotations
Simulink.allBlockDiagramsFind loaded Simulink models and libraries
modelfinderSearch and open examples, models, and projects (Since R2022a)
modelfinder.importDatabaseImport database to Model Finder (Since R2023b)
modelfinder.createDatabaseCreate new database to index models (Since R2023b)
modelfinder.setDefaultDatabaseSet default database to index models (Since R2023b)
modelfinder.setSearchDatabaseSet search scope to find models (Since R2023b)
modelfinder.searchFilterCreate Model Finder search filter (Since R2025a)
modelfinder.registerFolderIndex models in Model Finder (Since R2022a)
modelfinder.unregisterFolderRemove models from Model Finder (Since R2022a)
modelfinder.deleteDatabaseRemove database from Model Finder (Since R2023b)

Get Model Metadata

Simulink.MDLInfoExtract SLX, SLXP, or MDL file information without loading file
Simulink.MDLInfo.getDescriptionExtract SLX, SLXP, or MDL file description without loading file
Simulink.MDLInfo.getMetadataExtract SLX, SLXP, or MDL file metadata without loading file

Start Simulink

simulinkOpen Simulink Start Page
start_simulinkStart Simulink without opening any windows
isSimulinkStartedCheck whether Simulink is started (Since R2020b)
slLibraryBrowserOpen, load, and close Simulink Library Browser, create and get handle of Library Browser object

Create, Load, Open, Save, and Close Models

new_systemCreate Simulink model or library in memory
load_systemLoad Simulink model into memory
open_systemOpen model, library, subsystem, or block dialog box
save_systemSave Simulink model
close_systemClose Simulink model window or block dialog box
bdcloseClose any or all Simulink model windows unconditionally

Add, Replace, and Delete Blocks

add_blockAdd block to model
addtermsAdd terminators to unconnected ports in model
replace_blockReplace blocks in Simulink model
delete_blockDelete blocks from Simulink system
Simulink.BlockDiagram.deleteContentsDelete graphical contents of model
Simulink.SubSystem.deleteContentsDelete contents of subsystem

Connect Blocks

Simulink.connectBlocksConnect blocks with signal lines (Since R2024b)
add_lineAdd line to Simulink model
delete_lineDelete line from Simulink model

Edit Parameters

get_paramGet parameter names and values
set_paramSet Simulink parameter value
add_paramAdd parameter to Simulink model
delete_paramDelete model parameter added with add_param function
docblockGet or set editor invoked by Simulink DocBlock block

Configure Model Layout

Simulink.BlockDiagram.arrangeSystemImprove layout of block diagram
Simulink.BlockDiagram.routeLineRoute existing lines of model
Simulink.BlockDiagram.resizeBlocksToFitContentAdjust block size to fit displayed value (Since R2024b)

Group Model Elements into Subsystems

Simulink.BlockDiagram.createSubsystemCreate subsystem containing specified set of blocks
Simulink.BlockDiagram.expandSubsystemReplace subsystem with subsystem contents
Simulink.SubSystem.copyContentsToBlockDiagramCopy graphical contents from subsystem to another model
Simulink.SubSystem.deleteContentsDelete contents of subsystem
bdIsSubsystemDetermine whether model is subsystem
isSimulinkStartedCheck whether Simulink is started (Since R2020b)
bdIsLoadedDetermine whether model, subsystem, or library is loaded
bdIsDirtyDetermine whether model, subsystem, or library has unsaved changes
slIsFileChangedOnDiskDetermine whether model has changed since it was loaded
bdIsLibraryDetermine whether model is library
bdIsSubsystemDetermine whether model is subsystem
edittime.getDisplayIssuesCheck whether model design warnings and errors are on
edittime.setDisplayIssuesDetect model design errors and warnings

Use Model Templates

Simulink.exportToTemplateCreate template from model or project
Simulink.createFromTemplateCreate model or project from template
Simulink.findTemplatesFind model or project templates with specified properties
Simulink.defaultModelTemplateSet or get default model template

Export Models

Simulink.ModelReference.protectObscure referenced model contents to hide intellectual property
Simulink.exportToVersionExport model, library, or project for use in previous version of Simulink
Simulink.exportToTemplateCreate template from model or project
slCharacterEncodingSpecify encoding to use in code generated from Simulink models

Print Models

frameeditOpen PrintFrame Editor to edit print frames for Simulink and Stateflow block diagrams
orientPaper orientation for printing or saving
printPrint figure or save to specific file format

Objects

ModelFinderFilterModel Finder search filter (Since R2025a)
Simulink.AnnotationCreate and specify properties of text, image, and area annotations

Topics

Specify Objects to Edit Programmatically

Create Models

Format Models

Share Models