Main Content

Edit and Manage Workspace Variables by Using Model Explorer

要了解您可以使用的所有技术来创建,编辑和管理工作区变量,请参见创建,编辑和管理工作区变量

Finding Variables That Are Used by a Model or Block

在模型资源管理器中,您可以获取模型或块使用的变量列表。以下方法是获取变量列表的一种方法:

  1. In the内容pane, right-click the block for which you want to find the variables that it uses.

  2. 选择Find Referenced Variables菜单项。

模型资源管理器returns results similar to these:

为了性能,Model Explorer使用模型的最后一个编译版本中的缓存信息。如果要重新编译模型,则可以手动进行操作,或者在模型资源管理器中进行设置Update diagramfield to是的and repeat the search.

您还可以使用以下方法查找模型或块使用的变量:

  • In the Model Explorer, in theModel Hierarchypane, right-click a block or model node and select theFind Referenced Variables菜单项。

  • In the Model Explorer, in the search bar, use the用于引用变量搜索类型选项。

  • In the Simulink®编辑器,右键单击一个块,子系统或在画布中,然后选择Find Referenced Variables菜单项。单击整个模型的画布返回结果。

The金宝appsimulink.findvarsfunction provides additional options for returning information about workspace variables that is not available from the Model Explorer or Simulink Editor.

有关查找引用变量时限制的信息,请参阅金宝appsimulink.findvarsdocumentation.

Using the Set of Returned Variables

对于返回变量集中的变量,您可以找到使用该变量的块(有关详细信息,请参阅Finding Blocks That Use a Specific Variable)。另外,您可以从返回的变量集中导出变量。有关详细信息,请参阅出口Workspace Variables

Finding Blocks That Use a Specific Variable

This example shows how to use Model Explorer to get a list of blocks that use a specific workspace variable.

  1. Open the modelF14

  2. Open Model Explorer.

  3. In theModel Hierarchypane, select theBase Workspacenode.

  4. In the内容pane, right-click the variableMqand selectFind Where Used

  5. In theSelect a systemdialog box, selectF14

  6. Clear theSearch in referenced modelscheck box, sinceF14does not reference any models, and clickOK

    Search in referenced modelsselected, you can find the target variable everywhere it is used in a model reference hierarchy. However, finding the target variable in an entire hierarchy can take more time.

    TheUpdate diagram to include recent changescheck box is cleared by default to save time by avoiding unnecessary model diagram updates. Select the check box to incorporate recent changes you made to the model by forcing a diagram update.

  7. ClickOK响应消息以更新模型图。

    Because you just opened the model, you must update the model diagram at least once before finding a variable. You could have selectedUpdate diagram to include recent changesin theSelect a systemdialog box to force an initial diagram update, though you typically use that option when you make changes to the model while performing multiple searches withFind Where Used

  8. 模型Explorer显示搜索结果:

    其值包括的属性列Mqrepresent the block parameters that use theMqvariable. If those property columns are not already in the view, then the Model Explorer adds them to the end of the search results display.

You can also find blocks that use a specific variable by using one of these approaches:

  • In the search bar, select thefor Variable Usage搜索类型选项。

  • In the搜索结果窗格,右键单击变量,然后选择Find Where Used菜单项。

  • In the Model Data Editor, right-click a workspace variable and select theFind Where Used菜单项。

Finding Unused Workspace Variables

You can use the Model Explorer to get a list of variables that are defined in a workspace but not used by a model or block. One way to get that list of variables is to right-click a workspace name in theModel Hierarchypane and select the找到未使用的变量菜单项。例如:

  1. Open theF14model.

  2. 打开模型资源管理器。

  3. 在搜索工具栏,设置Update diagramfield to是的

  4. In theModel Hierarchypane, right-click theBase Workspacenode and select the找到未使用的变量菜单项。

  5. The Model Explorer displays output similar to this:

    The金宝appsimulink.findvarsfunction provides additional options for returning information about unused workspace variables that is not available from the Model Explorer or Simulink Editor.

Editing Workspace Variables

在模型资源管理器中,您可以使用变量编辑器从MATLAB编辑变量®基本工作区或模型工作区。可变编辑器可用于编辑大型阵列和结构。

To open the Variable Editor:

  1. In the内容pane, select the variable.

  2. In the Dialog pane (the right pane), click the buttonnear the value of the variable.

  3. In the menu, select打开的变量编辑器

或者,从内容pane instead of the Dialog pane, begin editing the value of the variable by clicking the appropriate cell. The button appears in the cell.

具有三个或更多维度的数组的表示

当变量的值或金宝appsimulink.parameter对象是一个具有三个或多个维度的数组,Value列显示数组作为包含调用的表达式reshape功能。

To edit the values in the array, modify the first argument of thereshape呼叫,其中包含序列化向量中的所有数组值。当您沿尺寸添加或删除元素时,还必须纠正表示修改尺寸长度的参数。

重命名变量

此示例显示了如何使用Model Explorer在Simulink模型中使用的块使用该变量。金宝app

  1. Open the建模防抱死制动系统示例模型sldemo_absbrake。该模型将数据加载到MATLAB基本工作区。

  2. Open Model Explorer.

  3. In theModel Hierarchypane, select the base workspace.

  4. In the内容pane, right-click the base workspace variablemand selectRename All

  5. In theSelect a system对话框,单击模型的名称sldemo_absbrake选择它作为重命名变量的上下文m

  6. Clear theSearch in referenced models复选框,然后单击OK。该模型sldemo_absbrakereferences the modelsldemo_wheelspeed_absbrake, but onlysldemo_absbrakeuses the variablem

    Search in referenced modelsselected, you can rename the target variable everywhere it is used in a model reference hierarchy. However, renaming the target variable in an entire hierarchy can take more time.

    TheUpdate diagram to include recent changescheck box is cleared by default to save time by avoiding unnecessary model diagram updates. Select the check box to incorporate recent changes you made to the model by forcing a diagram update.

  7. ClickOK响应消息以更新模型图。

    由于您刚刚打开了模型,因此必须在重命名变量之前至少更新一次模型图。你可以选择Update diagram to include recent changesin theSelect a systemdialog box to force an initial diagram update, though you typically use that option when you make changes to the model while performing multiple variable renaming operations.

  8. In theRename Alldialog box, type a new name for the variable in the新名字box and clickOK

    You can use the hyperlinks in theCorresponding blockssection of theRename All对话框以查看目标块。

Note

您可以重命名功能的变量金宝appsimulink.findvars金宝app支持。

为了帮助重命名文件,请使用项目。看重命名,删除或删除文件时自动更新

Compare Duplicate Workspace Variables

您可以比较存储在同一工作区或不同工作区中的重复变量。例如,您可以将存储在基本工作区中的变量与其重复的变量进行比较,该变量存储在模型工作区中。

  1. 打开模型和模型资源管理器。

  2. 在搜索工具栏中,搜索复制的变量。选择具有重复条目的行。然后,右键单击并选择比较选定的

  3. 查看差异Comparison Viewer

出口Workspace Variables

您可以导出(保存)模型资源管理器中列出的一组变量,导出单个变量或基础或模型工作区中的所有变量。

One possible workflow is to export the set of variables returned with theFind Referenced Variables选项或金宝appsimulink.findvars功能。有关详细信息,请参阅Finding Variables That Are Used by a Model or Block

Note

All the variables that you export must be from the same workspace.

To export all the variables in a workspace in the Model Explorer to a MATLAB code file or MAT-file:

  1. 选择要导出的变量。

    1. 要选择工作空间中的所有变量,请右键单击工作区节点(例如,Base Workspace) and select the出口菜单项。例如:

    2. To select individual variables, in the内容pane, select the variables that you want to export. Right-click one of the highlighted variables and select the出口Selected菜单项。

    如果是内容Pane的数据由属性分组,选择组中的顶行不会选择该组中的所有变量。有关分组数据的详细信息,请参阅模型资源管理器

  2. Specify whether to save the variables in a MATLAB code file or a MAT-file.

    The MATLAB code file format is easier to read, is editable, and supports version control. The MAT-file format is binary, which has performance advantages.

    If you specify a MATLAB code file format, the Model Explorer may create an associated MAT-file, reflecting the name of the MATLAB code file, but with an extension of。mat代替。m

  3. Specify a name and location for the file.

  4. 如果是file already exists, Model Explorer displays a dialog box asking you to choose one of these options:

    • Overwrite entire file

      • Replaces all variables in the target file with the selected variables, which are stored in alphabetical order.

    • 更新文件中存在的变量并附加新变量以文件

      • Updates existing variables in place and appends new variables.

    • Only update variables that exist in file

      • 更新现有变量,但不会添加任何新变量,从而消除了潜在的无关变量。

To permanently store workspace variables for a model, instead of using the base workspace, create a data dictionary. See什么是数据字典?

进口ing Workspace Variables

你可以导入(负载)fi的一组变量le into the base workspace or into a model workspace using the Model Explorer. When you import variables into a workspace, the Model Explorer overwrites existing variables and adds any new variables.

将变量导入工作空间:

  1. In theModel Hierarchypane, right-click the workspace into which you want to import variables.

  2. 选择进口菜单项。

  3. In the Import from File dialog box, select a MATLAB code file or MAT-file for the variables that you want to import.

    Note

    If you import a MATLAB code file, then Simulink also imports the associated MAT-file.

也可以看看

|

Related Topics