为 simulink 模型设置 PostCodeGenCommand 时出错

error when setting PostCodeGenCommand for a simulink model

我想在我的代码生成过程中添加一个 post-build 挂钩。但是,当我尝试将函数与 simulink 模型的 PostCodeGenCommand 相关联时,出现以下错误。

set_param(bdroot, 'PostCodeGenCommand', 'packNGo(buildInfo);')
A configuration set reference does not allow writing to parameters in the source configuration set

我不太理解错误消息,它也没有在我最喜欢的搜索引擎上显示任何有用的结果。谁能帮我破译一下?

不幸的是,我无法在简单的 simulink 模型上重现这个问题,即使我包含了一个参考模型。 (我想这可能是 "reference" 这个词,嗯,在错误消息中引用。我之前注意到引用模型的处理方式与 simulink 代码生成器中的其他模型不同。)

我使用的是 R2015a,但如果有帮助,可以访问较新的版本。

请注意,这个问题最初是在 Matlab forum 上 post 编辑的,但没有得到任何答案。

事实证明,该模型使用的是 "configuration reference" 而不是在内部存储其配置。模型资源管理器提供以下描述

Configuration Reference
A model may reference a 'Configuration set' that is defined in the 
source location rather than stored in the model....

这对我们很有用,因为我们使用的多个模型都共享相同的配置集。它保存在一个中央位置,所有更新立即应用于所有模型。

副作用是 bdroot 不再有与之关联的 PostCodeGenCommand。相反,我正在寻找的命令是

configurationSettings.set_param('PostCodeGenCommand', 'packNGo(buildInfo);')

其中 configurationSettings 是您工作区中的一个变量,该变量的名称应与模型资源管理器中的 "Referenced configuration set name" 匹配。