|
I found a possible bug with the Simulink.Bus.createObject method when you have a struct in the workspace that has nested structs that are multi-dimensional. For example,
S = <1x1 struct>
S.B = <1x2 struct>
S.B(1).id = 1
S.B(2).id = 2
or take the code:
S = struct
S.B = struct
S.B(1).id = 1
S.B(2).id = 2
Simulink.Bus.createObject(S)
And you get two bus objects: B and slBus1:
>> B.Elements
ans =
Simulink.BusElement
Name: 'id'
DataType: 'double'
Complexity: 'real'
Dimensions: [1 1]
DimensionsMode: 'Fixed'
SamplingMode: 'Sample based'
SampleTime: -1
>> slBus1.Elements
ans =
Simulink.BusElement
Name: 'B'
DataType: 'B'
Complexity: 'real'
Dimensions: 1
DimensionsMode: 'Fixed'
SamplingMode: 'Sample based'
SampleTime: -1
The problem here is that slBus1 has 2 elements but the Dimensions only show 1. I should have:
>> slBus1.Elements
ans =
Simulink.BusElement
Name: 'B'
DataType: 'B'
Complexity: 'real'
Dimensions: [1 2] <-- THIS
DimensionsMode: 'Fixed'
SamplingMode: 'Sample based'
SampleTime: -1
I need to create a bus object that represents my data precisely so I can use it in Simulink's Matlab Function block as a parameter. Otherwise, the way it works now creates problems since all nested structs are only 1 dimension and not [1 N] dimension based on the source data. When I try to use the parameter as a bus object, I get errors in Simulink because they differ. Is there any way to resolve this problem?
|