Thread Subject: Problem with Simulink.Bus.createObject?

Subject: Problem with Simulink.Bus.createObject?

From: Thomas Marullo

Date: 1 Dec, 2011 20:39:08

Message: 1 of 1

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?

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
bus Thomas Marullo 1 Dec, 2011 15:44:10
simulink Thomas Marullo 1 Dec, 2011 15:44:10
buses Thomas Marullo 1 Dec, 2011 15:44:10
struct Thomas Marullo 1 Dec, 2011 15:44:10
structures Thomas Marullo 1 Dec, 2011 15:44:10
nesting Thomas Marullo 1 Dec, 2011 15:44:10
rssFeed for this Thread

Contact us at files@mathworks.com