MATLAB Answers

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

15 views (last 30 days)
Joe
Joe on 27 Sep 2017
Commented: Pierre Bélissent on 12 Oct 2018
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.

Answers (2)

Suze Zhang
Suze Zhang on 9 Oct 2017
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 Comment
Pierre Bélissent
Pierre Bélissent on 12 Oct 2018
Thanks! Having the same issue. Is this capability (array of bus as a bus sub-element) available in newer versions?

Sign in to comment.


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

Community Treasure Hunt

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

Start Hunting!

Translated by