创建模块封装
自定义模块外观、用户界面和模块图
Simulink® 允许您创建模块封装。封装是用于模块的一种自定义用户界面。
通过封装模块,可以将模块图封装起来,使其拥有自己的参数对话框,以及自己的模块描述、参数提示和帮助文本。
您可以封装独立的自定义模块以作为独特模块重复使用,就像 Simulink 中定义的模块一样。
要了解如何创建模块封装,请参阅创建简单封装。
类
主题
封装简介
- 封装基础知识
了解有关封装和何时封装模块的基础知识。 - 创建简单封装
您可以使用封装编辑器以交互方式封装模块,也可以编程方式封装模块。此示例说明如何使用封装编辑器来封装模块。要以编程方式封装模块,请参阅以编程方式控制封装 - Manage Existing Masks
View or edit an existing block mask.
封装编辑器用户界面
- 封装编辑器概述
使用封装编辑器界面创建和自定义封装。 - 使用“数据类型字符串”参数指定数据类型
为“编辑封装”参数添加数据类型约束。 - 设计封装对话框
尝试此示例以创建一个封装对话框并了解某些封装编辑器功能的用途。 - Handling Large Number of Mask Parameters
Add large number of mask parameters in a Table programmatically. - Customize Tables for Masked Blocks
Add custom tables to mask dialog box. - Control Custom Table Programmatically
Use a programmatic interface to control custom tables. - 以编程方式控制封装
Simulink® 定义了一组有助于设置和编辑封装的参数。要从 MATLAB® 命令行设置和编辑封装,您可以使用Simulink.Mask
和Simulink.MaskParameter
类方法。也可以使用get_param
和set_param
函数来设置和编辑封装。但是,由于这些函数使用的分隔符不支持 Unicode®(非英文)字符,建议您使用Simulink.Mask
方法和Simulink.MaskParameter
类方法来控制封装。
封装功能
- Validating Mask Parameters Using Constraints
Add validation to mask parameters using constraints. - Custom Constraint for Mask Parameter
A mask can contain parameters that accept user input values. - Share Parameter Constraints Across Multiple Block Masks
This example shows how to create a parameter constraint and share it across masks of different blocks in the same model or different models. - Validate Input and Output Port Signals Using Port Constraints
You can validate compile-time signal attributes on the input and output ports of a masked block by using port constraints. - Validate Port Signals Among Ports of the Same Masked Block
This example shows how to create cross port constraints to validate compile-time signal attributes among ports of the same masked block. - Share Port Constraints Across Multiple Masked Blocks
This example shows how to create a port constraint and share it across masks of different blocks in the same model or different models. - 封装回调代码
添加并执行封装回调代码。 - 从封装初始化和回调代码开始
使用 MATLAB® 代码初始化模块封装。 - Promote Block Parameters on a Mask
Blocks and subsystems can have multiple parameters associated with them. - 将值传递给封装下的模块
使用封装对话框指定输入值。 - Mask Linked Blocks
Add custom interface to linked blocks. - Approaches to Control Active Variant Choice of a Variant Block Using Mask or Model Workspace
This example shows different approaches to control the active choice of inline variant and Variant Subsystem blocks from a mask or a model workspace. - Define Measurement Units for Masked Blocks
Set measurement units for output and input ports of a masked block. - Add Images in Masks
Add images as mask icons and save them in the SLX file. - Create Hierarchical List in Mask Dialog
Create a hierarchical list of data on a mask. - Tune Mask Enumeration Parameters - Popup and Radio Button
Reference external enumeration file to assign numerical values to popup parameter. - Visualize and Plot N-Dimensional Data Using Mask Lookup Table Control
Use a lookup table to evaluate a sampled representation of a function using simple lookup operations. - Preserve Tunability of Parameters That Are Modified or Created in Mask Initialization
A desirable feature of code generated from a model is the ability to tune variables to different values.
图形图标编辑器
- Graphical Icon Editor Overview
Create and edit mask icon of a block in a graphical environment. - Create and Edit Block Mask Icon
Create block mask icon using Graphical Icon Editor and Mask Drawing commands. - Add Dynamic Behavior to Masked Icons
Using Graphical Icon Editor, you can add dynamic behavior to masked block icons:
封装回调
- 从封装初始化和回调代码开始
使用 MATLAB 代码初始化模块封装。 - Author Mask Initialization and Callbacks
You can write MATLAB code in the code pane of the Mask Editor for mask initialization and callbacks. - Organize Mask Initialization and Callbacks in a MATLAB File
You can organize mask initialization and mask callback code in a separate MATLAB® class file. - 动态封装对话框
您可以为封装模块创建对话框,这些对话框的显示会根据用户输入而发生变化。以这种方式变化的封装对话框的特性包括: - 动态封装子系统
创建可以修改其结构性内容的封装库模块。 - Debug Masks That Use MATLAB Code
Troubleshoot errors in the mask initialization code.
系统封装
- Introduction to System Mask
Learn about masking a model. - 以编程方式控制封装
Simulink® 定义了一组有助于设置和编辑封装的参数。要从 MATLAB® 命令行设置和编辑封装,您可以使用Simulink.Mask
和Simulink.MaskParameter
类方法。也可以使用get_param
和set_param
函数来设置和编辑封装。但是,由于这些函数使用的分隔符不支持 Unicode®(非英文)字符,建议您使用Simulink.Mask
方法和Simulink.MaskParameter
类方法来控制封装。 - Create and Reference a Masked Model
Mask a model interactively. - Create and Display System Mask Programmatically
You can apply a system mask to a model or a subsystem block diagram.
示例模型
- Masking Example Models
View Simulink models that demonstrate masking capabilities.