Why can't I use a bus with an array subelement?

2 ビュー (過去 30 日間)
Joe
Joe 2017 年 9 月 27 日
コメント済み: Pierre Bélissent 2018 年 10 月 12 日
Hello,
I've created a structure 'myStruct' and an associated bus called 'myStruct_Bus' successfully, however, when I try to use 'myStruct' as a constant on a Simulink Diagram after having set the data type to 'Bus: myStruct_Bus' I get the error "Invalid setting in... for parameter 'Value'". It's a legitimate struct and a legitimate Bus. Why the error?
(NOTE: I'm using 32-bit Matlab/Simulink R2015a on Windows 7 Professional 64-bit with Service Pack 1)
Here's the code:
myStruct = struct;
myStruct.aa = 0;
myStruct.bb = 0;
myStruct.cc = 0;
myStruct.sub = struct;
myStruct.sub(1).a = 0;
myStruct.sub(1).b = 0;
myStruct.sub(1).c = 0;
myStruct.sub(2).a = 0;
myStruct.sub(2).b = 0;
myStruct.sub(2).c = 0;
myStruct.sub(3).a = 0;
myStruct.sub(3).b = 0;
myStruct.sub(3).c = 0;
if ~exist('pSysParams_Bus')
busInfo_myStruct = Simulink.Bus.createObject(myStruct);
% get root Bus
tmp = who('slBus*');
for i=1:length(tmp)
if isempty(strfind(tmp{i}, '_'))
break;
end
end
myStruct_Bus = eval(tmp{i}); clear(tmp{i});
end
Notice that the Bus Editor confirms the array size of 3.

回答 (2 件)

Suze Zhang
Suze Zhang 2017 年 10 月 9 日
Hi Joe,
As of Simulink 8.1 (R2013a), it is possible to create a Simulink bus in which one of its fields is an array of buses. However, it is not available in Simulink R2015a to initialize a Simulink bus that contains a field which is an array of buses. As a workaround, you can create the buses separately, concatenate them using the Vector Concatenate block, and then include the array of buses in larger bus.
I have attached a zipped folder 'example.zip' for this workaround. The model 'sub_bus_example.slx' uses the Simulink.Bus objects that are defined in the 'busInfo.mat' file, and the 'makeStruct.m' script shows how to make these Simulink.Bus objects. Note that you can nest this structure further.
Suze
  1 件のコメント
Pierre Bélissent
Pierre Bélissent 2018 年 10 月 12 日
Thanks! Having the same issue. Is this capability (array of bus as a bus sub-element) available in newer versions?

サインインしてコメントする。


Joe
Joe 2017 年 10 月 10 日
Thanks Suze. I'll take a look. Is this capability available in newer versions?

カテゴリ

Help Center および File ExchangeSources についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by