【发布时间】:2018-01-14 03:43:28
【问题描述】:
我正在使用 MATLAB 2013b,并且我正在尝试编写一个脚本,该脚本将自动将 ToWorkspace 块连接到一组选定的信号。
我可以处理信号的查找/获取句柄、添加块、设置变量名等等。然而,我想做的是以编程方式发现所选信号是标量、数组还是总线信号。这样,我可以将数组重塑为一维数组(以便它们以我想要的方式连接)并将总线信号分解为它们的单个元素。
我尝试了在See if a signal originates from a bus in Simulink 上发布的修复,但没有成功。我敢打赌,这篇文章已经足够老了,建议的修复在我尝试使用的 MATLAB 版本中不起作用。
我知道答案涉及编译模型或使用特定命令更新模型,但我被卡住了。请帮忙!
根据上面的链接,这是我尝试做的:
function usedNames = addToWorkspaceBlock( signal, usedNames )
% Recursively add whatever blocks are necessary to break down the signal
% into raw bus elements or reshaped arrays and output them that way
switch upper( get(signal,'CompiledBusType') )
case 'NOT_BUS'
% Will add the reshape block and ToWorkspace block here, saving
% the name of the ToWorkspace VariableName to usedNames
keyboard % for debugging
case {'VIRTUAL_BUS','NON_VIRTUAL_BUS'}
% Will add the reshape block and ToWorkspace block here, saving
% the name of the ToWorkspace VariableName to usedNames
keyboard % for debugging
otherwise
error('Unrecognized CompiledBusType %s', get(signal,'CompiledBusType'));
end
end
我得到的错误是这样的:(忽略行号;我的 addToWorkspaceBlock() 函数是我的主要函数的子函数,它处理获取信号并循环它们)
Error using createToWorkspaceBlocks>addToWorkspaceBlock (line 48)
line does not have a parameter named 'CompiledBusType'
Error in createToWorkspaceBlocks (line 36)
usedNames = addToWorkspaceBlock( signals(i), usedNames );
【问题讨论】:
-
为了帮助其他人回答您的问题,请在问题中发布您的格式化代码。
标签: matlab command signals simulink bus