主要内容

Simulink.data.dictionary.closeAll

R2026b

关闭与所有打开的数据字典的连接

描述

Simulink.data.dictionary.closeAll 尝试关闭与所有已打开的数据字典的所有连接。例如,如果您创建引用某个字典的对象(例如 Simulink.data.Dictionary),则该字典就是打开的。

某些命令和函数(例如 Simulink.data.dictionary.cleanupWorkerCache)在字典打开时无法运行。最佳做法是使用函数和方法(例如 Simulink.data.Dictionary 对象的 close 方法)逐个关闭每个连接。要查找已打开的字典,请使用 Simulink.data.dictionary.getOpenDictionaryPaths。不过,您可以使用此函数关闭与所有字典的所有连接。

您还可以使用此函数在属于工程的关闭脚本中关闭字典。

Simulink.data.dictionary.closeAll(dictFileName) 关闭与名为 dictFileName 的字典的所有连接。如果您打开使用此文件名的多个字典(例如,如果这些字典具有不同的文件路径),则该函数会关闭与所有这些字典的所有连接。

您不能将 dictFileName 指定为文件的完整路径,例如 'C:\temp\myDict.sldd'。

Simulink.data.dictionary.closeAll(___,unsavedAction) 在关闭与目标字典的所有连接时会丢弃或保存未保存的更改。您可以选择保存或丢弃对所有目标字典的所有更改。

示例

示例

全部折叠

丢弃任何未保存的更改。字典中的所有条目都还原到上次保存的状态。

Simulink.data.dictionary.closeAll('-discard')

打开与某个数据字典的多个连接,进行更改,并通过丢弃未保存的更改来关闭所有连接。

在命令提示符下,通过创建引用一个数据字典的 Simulink.data.Dictionary 对象来打开该字典。

例如,打开Using a Data Dictionary to Manage the Data for a Fuel Control System示例数据字典。

openExample('simulink_automotive/UseDDForFuelContSysExample')
dictObj = Simulink.data.dictionary.open('sldemo_fuelsys_dd.sldd');

在模型资源管理器中显示该字典

show(dictObj)

您现在有两个与此字典的连接:Simulink.data.Dictionary 对象和模型资源管理器。

通过添加条目对该字典进行更改。

dDataSectObj = getSection(dictObj,'Design Data');
addEntry(dDataSectObj,'myEntry',5.2);

Simulink.data.dictionary.Section 对象 dDataSectObj 是与该字典的第三个连接。

关闭与该字典的连接。丢弃未保存的更改。

Simulink.data.dictionary.closeAll('sldemo_fuelsys_dd.sldd','-discard')

该字典不再在模型资源管理器的模型层次结构窗格中显示为节点。Simulink.data.Dictionary 对象 dictObj 与该字典断开连接。您无法通过使用 Simulink.data.dictionary.Section 对象 dDataSectObj 与该字典交互。

清除引用该字典的对象。

clear dictObj dDataSectObj

输入参数

全部折叠

目标数据字典的文件名,指定为字符向量。使用文件扩展名 sldd。

示例: 'myDict.sldd'

数据类型: char

对未保存更改的操作,指定为 '-discard'(丢弃更改)或 '-save'(保存更改)。如果您不带 unsavedAction 参量调用 Simulink.data.dictionary.closeAll 函数,则当数据字典有未保存的更改时,Simulink® 会报告错误。

提示

如果满足以下任一条件,则数据字典处于打开状态:

  • 该字典在模型资源管理器的模型层次结构窗格中显示为节点。要关闭与该字典的此连接,请在模型资源管理器中右键点击此节点,然后选择关闭。或者,使用 Simulink.data.Dictionary 对象的 hide 方法。

  • 您创建了引用该字典的以下任一类的对象:

    • Simulink.data.Dictionary

    • Simulink.data.dictionary.Section

    • Simulink.data.dictionary.Entry

    要关闭与字典的这些连接,请使用 Simulink.data.Dictionary 对象的 close 方法或清除该对象。清除 Simulink.data.dictionary.Section 和 Simulink.data.dictionary.Entry 对象。

  • 链接到该字典的模型处于打开状态。要关闭与该字典的此连接,请关闭模型。

版本历史记录

在 R2016a 中推出