Create bus objects from blocks or MATLAB structures


busInfo = Simulink.Bus.createObject(model,blocks)
busInfo = Simulink.Bus.createObject(struct)
busInfo = Simulink.Bus.createObject(___,file)
busInfo = Simulink.Bus.createObject(___,format)



busInfo = Simulink.Bus.createObject(model,blocks) creates bus objects (instances of Simulink.Bus class in the MATLAB® base workspace) for specified blocks, and returns information about the objects that it created.

busInfo = Simulink.Bus.createObject(struct) creates bus objects in the MATLAB workspace from a MATLAB structure of timeseries objects or a numeric MATLAB structure.

busInfo = Simulink.Bus.createObject(___,file) saves the bus objects in a MATLAB file that contains a cell array of cell arrays. Each subordinate cell array represents a bus object and contains this data:

  • Bus name

  • Header file

  • Description

  • Data scope

  • Alignment

  • Elements

The elements field is an array containing this data for each element:

  • Element name

  • Dimensions

  • Data type

  • Sample time

  • Complexity

  • Dimensions mode

  • Minimum

  • Maximum

  • Units

  • Description

busInfo = Simulink.Bus.createObject(___,format) saves the bus objects in a file that contains either a cell array of bus information, or the bus objects themselves.


Use Bus Creator Blocks to Create a Bus Object

Create a bus object from the Bus Creator block called Bus Creator2.

bus2Info = Simulink.Bus.createObject...
('busdemo','busdemo/Bus Creator2')

Create a bus object from two Bus Creator blocks, using block handles to specify the blocks. Assign the block handles to variables and use the variables in a vector to specify the blocks used for creating the bus object.

Open the model.


In the Simulink® Editor, select the Bus Creator2 block. In MATLAB, assign the block handle to a variable.

bc2 = gcbh;

In the Simulink Editor, select the Bus Creator block. In MATLAB, assign the block handle to a variable.

bc1 = gcbh;

Use the block handle variables in a vector to create a bus object.

bus3Info = Simulink.Bus.createObject...
('busdemo', [bc2 bc1], 'busdemo_busobject')

Create Bus Objects from Cell Array of Bus Information

Create a cell array of cell arrays of bus information, and use that cell array to generate a bus object in the base workspace.

Create a cell array of bus information.

busCell = { ...
        { ...
            'myBusObj', ...
            'MyHeader.h', ...
            'My description', ...
            'Exported', ...
            '-1', ...
            {{'a',1,'double', [0.2 0],'real','Frame'}; ...
            {'b',1,'double', [0.2 0],'real','Sample'}},...
            }, ...

Generate a bus object in the base workspace from the cell array.


Input Arguments

collapse all

Model name or handle, specified as a character vector.

Blocks to create bus object for, specified as a character vector, cell array of block pathnames, or vector of block names.

  • For just one block, specify the full path name of the block.

  • For multiple blocks, specify either a cell array of block pathnames or a vector of block names.

  • If you specify a Bus Creator block that is at the highest level of a bus hierarchy, the function creates bus objects for all buses in the hierarchy.

Structure used to create bus objects, specified as a structure of MATLAB timeseries objects or a numeric structure.

File to save bus objects in, specified as a character vector. The file name must be unique. If you omit this argument, the function saves the created bus objects in a cell array, not in a file.

Format for storing bus objects in file, specified as either 'cell' or 'object'. The cell format is more compact, but the cell format is easier to read.

Output Arguments

collapse all

Bus information for specified blocks, returned as a structure array. Each element of the structure array corresponds to one block and contains these fields:

  • block – Handle of the block

  • busName – Name of the bus object associated with the block


If you specify a model name, the model must compile successfully before you use the Simulink.Bus.createObject command.

Introduced before R2006a

Was this topic helpful?