Documentation

Contents

Simulink.Bus.createObject

Create bus objects from blocks or MATLAB structures

Syntax

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)

Description

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, SamplingMode, DimensionsMode, Min, Max,DocUnits, Description}

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.

Tips

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

Input Arguments

modelName

Name or handle of a model

blks

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.

fileName

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

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'

structTimeseries

MATLAB timeseries structure variable used to create bus objects

structNumeric

Numeric structure variable used to create bus objects

Output Arguments

busInfo

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

Examples

Use Bus Creator Blocks to Create a Bus Object

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

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

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).

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

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';
open_system(model);
sim(model);
topOut
topOut = 

  Simulink.SimulationData.Dataset
  Package: Simulink.SimulationData

  Characteristics:
              Name: 'topOut'
    Total Elements: 3

  Elements:
    1: 'COUNTERBUS'
    2: 'OUTERDATA'
    3: 'INCREMENTBUS'

  -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);
close_system(model);

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

X = struct('a',1,'b',2)
bus3Info = Simulink.Bus.createObject(X)
Was this topic helpful?