Main Content

交互构建和编辑模型

了解如何创建模型,将块添加到模型,连接块并模拟模型的基础知识。您还将学习如何使用子系统,命名模型的一部分并修改模型来组织模型。

有关如何连接块并交互添加端口的摘要,请参见keyboard Shortcuts and Mouse Actions for Simulink Modeling

创建模型

  1. 在Simuli金宝appnk上®Start Page, choose a template or search the templates.

    Model templates are starting points that you can use to apply common modeling approaches. They help you reuse settings and block configurations. Use model and project templates to ensure your designs are applying best practices and to take advantage of previous modeling solutions.

    单击模板的标题以阅读说明。

    Simulink start page with the Digital Filter template title selected, and the description of the template showing

    Search for templates by entering text in the search box. You can enter flexible search options, including OR, AND, NOT, use wildcards, do a fuzzy search (~), and more. Use the Lucene search engine query parser syntax.

    To locate templates that are not on the MATLAB search path, click打开。模型模板具有扩展名。sltx

  2. After selecting the template you want, clickCreate Model

    要在不阅读描述的情况下使用模板,请单击模板图像。或者,按Ctrl+nto use your default template.

    A new model using the template settings and contents opens in the Simulink Editor.

如果内置模板不满足您的需求,请尝试在Examplestab or creating your own templates. See从模型创建模板。在Examples选项卡,输入搜索术语以搜索示例的标题和描述,或单击网络上打开示例查看全部旁边是产品名称。

Set Default Template for New Models

您可以指定用于所有新型号的模型模板。

  1. Create a model with the configuration settings and blocks you want, then export the model to a template. See从模型创建模板

  2. 要在每个新模型中重复使用这些设置,请使用Simulink启动页面或金宝app金宝appsimulink.defaultModeltemplate功能。

    在开始页面上,单击模板的标题以展开描述,然后单击旁边的下箭头Create Model并选择设为默认

    Simulink start page with the Digital Filter template title selected, and the Create Model menu of the template expanded to show the Set as Default option

设置默认模型模板后,每个新模型都使用该模板,例如,当您按Ctrl+n,当您使用新型号按钮或使用时new_system。在Simuli金宝appnk编辑器中,您的默认模板出现在列表的顶部。Simulation选项卡,您选择new

默认模板在开始页面上显示一个复选标记。

金宝appSimulink Start Page模板框,带有模板标题上方的复选标记

打开模型

打开模型将模型加载到内存中,并将其显示在Simulink编辑器中。金宝app使用这些技术中的任何一种:

  • 在MATLAB工具条上,在选项卡,单击金宝app。在Simuli金宝appnk开始页面上,从列表中选择最新模型或项目,或单击打开

  • In the Simulink Toolstrip, on theSimulationtab, select打开and click最近的文件to open recent files or打开搜索模型。

  • 在MATLAB命令窗口中,在没有文件扩展名的情况下输入模型的名称,例如vdp。该模型必须在当前文件夹或MATLAB搜索路径中。

  • In the Simulink Library Browser, click the打开按钮

  • 打开the model using the Current Folder browser or your operating system file browser.

笔记

To open a model created in a later version of Simulink software in an earlier version, first export the model to the earlier version. SeeExport Model to Previous Simulink Version

Set Favorite Files

Set favorites to easily find your favorite models and projects on the Simulink Start Page.

In theRecentlist, you can add files to favorites. TheFavorites然后列表在开始页面上显示的最新文件之上,因此您可以轻松地重新打开自己喜欢的模型和项目。

Simulink start page showing a model name in the Recent list, and the cursor hovering to the right of the name over a star symbol with the tooltip text Add to favorites

清除最近的文件

要编辑或清除开始页面上的最新文件列表,请右键单击一个最近的文件,然后单击Remove from ListorClear List

Alternatively, useSimulink.history.clear以编程方式清除模拟历史记录金宝app。

打开模型时负载变量

当您构建模型时,有时会为模型定义变量。例如,假设您有一个包含增益块的模型。您可以指定变量k作为增益而不是在块上设置值。当您使用这种方法时,必须定义变量k为了模拟模型。

打开模型时,您可以使用模型回调来加载变量。

  1. In a model that uses the Gain block, set the blockGain价值为k

  2. Define the variable in a MATLAB script. In MATLAB, selectnew>Script。In the script, enter your variable definitions:

    k=27

  3. Save the script asloadvar.m

  4. In the model, open the Property Inspector. On the造型标签,下设计, click物业检查员

  5. 在模型的最高级别,单击Simulink编辑器帆布中的空白空间,以确保没有选择任何内容。金宝app

  6. 特性tab, in theCallbacks部分,选择预载体,然后输入loadvar

  7. 保存模型。

    下次您打开模型时PreloadFcn回调将变量加载到MATLAB工作区中。

您还可以使用“模型属性”对话框,而不是属性检查器。在造型选项卡,单击模型设置>模型属性

To learn about callbacks, seeCallbacks for Customized Model Behavior。要定义以编程加载变量的回调,请参见Programmatically Load Variables When Opening a Model

打开模型That Has Different Character Encoding

If you open an MDL file created in a release prior to R2021b in a MATLAB session that uses different encoding, you receive a warning. For example, suppose you create an MDL file in a MATLAB session configured forShift_JISand open it in a session configured forwindows-1252。The warning message displays the encoding of the current session and the encoding used to create the model. Starting in R2021b, MDL files, similar to SLX files, can store characters from any encoding. Resave your model files as MDL or SLX files.

金宝app模型文件类型

新型号具有.slxextension by default. Models created before R2012b have the extension.mdl。您可以用任何一个.slxor.mdlextension, depending on when they were created and whether you converted them. SeeSave Models in the SLX File Format

.slxpand.mdlpextensions denote protected models that you cannot open or edit. See来自第三方的参考保护模型。模型模板具有扩展名。sltx

金宝app李仿真软件braries and subsystems can also use the.slxextension. To learn more, see在模型组件的类型中选择

也可以看看

||||

Related Topics