Create bus objects from blocks or MATLAB structures


busInfo = Simulink.Bus.createObject(modelName, blks)
busInfo = Simulink.Bus.createObject(modelName,blks,fileName)
busInfo = Simulink.Bus.createObject(modelName,blks,fileName,format)
busInfo = Simulink.Bus.createObject(structTimeseries,fileName,format)
busInfo = Simulink.Bus.createObject(structNumeric,fileName,format)


busInfo = Simulink.Bus.createObject(modelName, blks) 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(modelName,blks,fileName) saves the bus objects in a MATLAB file that contains a cell array of cell arrays. Each subordinate array represents a bus object and contains the following data:

{BusName, HeaderFile, Description, DataScope, Alignment, Elements}

The Elements field is an array containing the following data for each element:

{ElementName, Dimensions, 
DataType, SampleTime, 
Complexity, DimensionsMode, Min, 

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

busInfo = Simulink.Bus.createObject(structTimeseries,fileName,format) creates bus objects in the MATLAB workspace from a MATLAB structure of timeseries objects and optionally saves the bus objects in the specified file.

busInfo = Simulink.Bus.createObject(structNumeric,fileName,format) creates bus objects in the MATLAB workspace from the numeric MATLAB structure and optionally saves the bus objects in the specified file.


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

Input Arguments


Name or handle of a model


List of subsystem-level Inport blocks, root-level or subsystem-level Outport blocks or Bus Creator blocks in the specified model. If only one block needs to be specified, this argument can be the full pathname of the block. Otherwise, this argument can be either a cell array containing block pathnames or a vector of block handles.

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


Name of the file in which to save the bus objects created by this function. The file name must be unique. If you omit this argument, the function save the created bus objects in a cell array, not in a file.


Format used to store the bus objects. The value can be 'cell' or 'object'. Use cell array format to save the objects in a compact form.

Default: 'cell'


MATLAB timeseries structure variable used to create bus objects


Numeric structure variable used to create bus objects

Output Arguments


A structure array containing bus information for the specified blocks. Each element of the structure array corresponds to one block and contains the following fields:

blockHandle of the block
busNameName of the bus object associated with the block


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. In the Simulink® Editor, select the Bus Creator2 block and then the Bus Creator block and assign their block handles to variables. Use those variables in a vector specify the blocks to use for creating the bus object. This example also shows how to specify a file for saving the output (busdemo_busobject).

% Select the Bus Creator2 block
bc2 = gcbh;
% Select the Bus Creator block
bc1 = gcbh;
bus3Info = Simulink.Bus.createObject...
('busdemo', [bc2 bc1], 'busdemo_busobject')

Use a Structure of Timeseries Objects to Create a Bus Object

Create a bus object from a MATLAB structure of timeseries objects that results from logged data for the COUNTERBUS bus signal.

model = 'sldemo_mdlref_bus';
topOut = 

  Package: Simulink.SimulationData

              Name: 'topOut'
    Total Elements: 3

    2: 'OUTERDATA'

  -Use get or getElement to access elements by index or name.
  -Use addElement or setElement to add or modify elements.

  Methods, Superclasses
bus4Info = Simulink.Bus.createObject(topOut.get('COUNTERBUS').Values);

Create a bus object from a MATLAB structure, independent of a model.

X = struct('a',1,'b',2)
bus3Info = Simulink.Bus.createObject(X)

Introduced before R2006a

Was this topic helpful?