编程式模型编辑
使用 API 执行建模基础操作,例如添加、配置和连接模块
您可以通过编程方式创建、编辑、搜索和检查 Simulink® 模型。要以编程方式与模型交互,必须已加载模型。创建或打开模型也会加载模型。使用“创建模型”下列出的函数来创建、加载或打开模型。然后,使用本页上的其他函数以编程方式编辑模型及其内容。在函数输入参量中,将希望函数编辑的对象指定为句柄、路径或文件名。此目标对象可以是模型、子系统或库等组件,或者是模块或信号线等模型元素。您可以指定已知其名称和位置的目标对象,也可以通过编程方式搜索符合特定条件的目标对象。有关详细信息,请参阅函数文档和Get Handles and Paths。
当您要与第三方共享模型而又不泄露知识产权时,请使用 Simulink.ModelReference.protect
(Embedded Coder) 函数创建模型的受保护版本。有关详细信息,请参阅保护模型以隐藏内容 (Embedded Coder)。
有关如何以编程方式运行仿真的信息,请参阅以编程方式运行仿真。要以编程方式创建和编辑工程,请参阅以编程方式创建和编辑工程。要以编程方式配置 Simulink 编辑器,请参阅Programmatic Model Editor Appearance Parameters。要从 MATLAB® 命令行窗口调试仿真,请参阅以编程方式调试仿真。
函数
对象
ModelFinderFilter | Model Finder search filter (自 R2025a 起) |
Simulink.Annotation | 创建并指定文本注解、图像注解和区域注解的属性 |
主题
以编程方式指定要编辑的对象
- 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, 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. - 以编程方式指定模块参数和属性
要编写修改模块行为的脚本,请确定模块参数和属性的编程名称和支持的值。
格式化模型
- 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. - 以编程方式控制封装
以编程方式指定和编辑模块封装。
共享模型
- 以编程方式打印模型
使用 MATLABprint
命令打印 Simulink 模型。