主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

Simulink.data.dictionary.closeAll

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

说明

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'(保存更改)。如果调用 Simulink.data.dictionary.closeAll 时没有使用 unsavedAction 参量,且数据字典中有未保存的更改,则 Simulink® 会报告错误。

提示

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

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

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

    • Simulink.data.Dictionary

    • Simulink.data.dictionary.Section

    • Simulink.data.dictionary.Entry

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

  • 已打开与字典链接的模型。要关闭与字典的连接,请关闭模型。

版本历史记录

在 R2016a 中推出