Simulink.Bus.createObject

Package: Simulink.Bus

Create bus objects from blocks or MATLAB structures

Description

example

busInfo = Simulink.Bus.createObject(model,blocks) creates Simulink.Bus objects for specified blocks and returns information about the created bus objects. These bus objects go in the MATLAB® base workspace or, if available, the data dictionary used by the model.

busInfo = Simulink.Bus.createObject(struct) creates bus objects from a structure that can contain MATLAB timeseries, MATLAB timetable, and matlab.io.datastore.SimulationDatastore objects or a numeric structure. These bus objects go in the MATLAB base workspace or, if available, the data dictionary used by the model.

example

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.

Examples

collapse all

Open the model.

open_system('busdemo')

Create a bus object that corresponds with the bus created by the Bus Creator2 block.

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.

open_system('busdemo')

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;

To create a bus object, use the block handle variables in a vector.

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

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 path names, or vector of block handles.

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

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

  • 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 that can contain MATLAB timeseries, MATLAB timetable, and matlab.io.datastore.SimulationDatastore objects or a numeric structure.

MATLAB file used to save bus object definitions, specified as a character vector. The file name must be unique.

Format for storing bus objects in file, specified as either 'cell' or 'object'. The cell format is more compact, but the object 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

Tips

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

Compatibility Considerations

expand all

Not recommended starting in R2019b

Introduced before R2006a