Main Content

Simulink.Bus.createObject

CreateSimulink.Busobjects from blocks or MATLAB structures

Description

example

busInfo= Simulink.Bus.createObject(model,blocks)createsSimulink.Busobjects for the specified blocks and returns information about the createdBusobjects.

If you specify a block that corresponds to a bus hierarchy, this function createsBusobjects for each bus in the hierarchy.

If the model uses a data dictionary, theBusobjects are created in the data dictionary. Otherwise, they are created in the base workspace.

example

busInfo= Simulink.Bus.createObject(struct)createsBusobjects from a structure that can contain MATLAB®timeseries, MATLABtimetable, andmatlab.io.datastore.SimulationDatastoreobjects or a numeric structure.

If you specify a structure with hierarchy, this function createsBusobjects for each structure in the hierarchy.

Busobjects are created in the base workspace.

example

busInfo= Simulink.Bus.createObject(___,file)savesBusobjects in a function that defines object properties in a cell array of cell arrays, then creates theBusobjects by callingSimulink.Bus.cellToObject.

Specify any of the input argument combinations in the previous syntaxes followed by thefileargument.

example

busInfo= Simulink.Bus.createObject(___,file,format)savesBusobjects in a function with the specified format. The function can define object properties using cell arrays or arrays.

busInfo= Simulink.Bus.createObject(struct,file,format,scope)creates theBusobjects in the data dictionary specified byscope.

Examples

collapse all

Open the example model.

open_system(" BusObjectCreationModel')

Create aBusobject that corresponds with the bus created by the Bus Creator block.

busInfo = Simulink.Bus.createObject(" BusObjectCreationModel',..." BusObjectCreationModel/Bus Creator');

CreateBusobjects from two Bus Creator blocks and save theBusobject definition in a function.

Open the example model.

open_system(" BusObjectCreationModel');

Assign the block handle for the Bus Creator block to a variable with thegetSimulinkBlockHandlefunction.

bc = getSimulinkBlockHandle(" BusObjectCreationModel/Bus Creator');

Alternatively, you can select a Bus Creator block in the model then use thegcbhfunction to get its block handle.

Assign the block handle for the Bus Creator1 block to a variable.

bc1 = getSimulinkBlockHandle(" BusObjectCreationModel/Bus Creator1');

To create aBusobject, specify the block handle variables in a vector. To save theBusobject definition, also specify a file name.

busInfo = Simulink.Bus.createObject(" BusObjectCreationModel',...[bc bc1]," BusObjectFunction');

Since these Bus Creator blocks create a bus hierarchy, specifying only the Bus Creator1 block creates bothBusobjects in the Workspace and in the function.

Compare theBusObjectFunctionagainst the function created by this command.

topBusInfo = Simulink.Bus.createObject(" BusObjectCreationModel',...bc1," BusObjectFunctionFromHierarchy');

For a function that is formatted to be easier to read, specify the function format asobject.

topBusInfo1 = Simulink.Bus.createObject(" BusObjectCreationModel',...bc1," BusObjectFunctionFormatted','object');

When you create a nonvirtual bus with a Constant block, you must specify a MATLAB structure forConstant valueand aSimulink.Busobject as theOutput data type.

For this example, create a structure that contains other structures.

bus_struct.A.A1 = 0; bus_struct.A.A2 = [0 + 0i;0 + 0i;0 + 0i;0 + 0i;0 + 0i]; bus_struct.B = 5; bus_struct.C.C1 = 0; bus_struct.C.C2.A1 = 0; bus_struct.C.C2.A2 = [0 + 0i;0 + 0i;0 + 0i;0 + 0i;0 + 0i];

Create theBusobjects that correspond with the structure.

busInfo = Simulink.Bus.createObject(bus_struct);

的函数创建urBusobjects. TheBusobject namedslBus1corresponds to the top-level structure and uses a defaultBus对象名称。的Busobjects namedA,C, andC2correspond to the nested structures.

To view theBusobjects, open the Bus Editor.

buseditor

Input Arguments

collapse all

Model name or handle, specified as a character vector.

的model you specify must compile successfully.

Blocks associated with buses, specified as a character vector, cell array of block path names, or vector of block handles. For 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.

这个函数可以创建Busobjects from these blocks:

  • Bus Creatorblocks

  • SubsystemInportblocks

  • SubsystemOutportblocks

If you specify a block associated with a bus hierarchy, the function also createsBusobjects for all nested buses in the hierarchy.

Structure of objects or numeric structure, specified as a structure that can contain MATLABtimeseries, MATLABtimetable, andmatlab.io.datastore.SimulationDatastoreobjects or a numeric structure.

Name of function being generated, specified as a character vector. The file name must be unique.

Format of function being generated, specified as either'cell'or'object'. The'cell'format is more compact, but the'object'format is easier to read.

'cell'format saves theBusobject definitions in a cell array of cell arrays and creates theBusobjects by callingSimulink.Bus.cellToObject. Each subordinate cell array represents aBusobject and contains these properties:

  1. Bus name

  2. Header file

  3. Description

  4. Data scope

  5. Alignment

  6. Preserve Element Dimensions

  7. Elements

的elements field is a cell array that contains this information for each of theSimulink.BusElementobjects that theBusobject references:

  1. Element name

  2. Dimensions

  3. Data type

  4. Sample time — The cell array contains this field when the sample time is not inherited. A noninherited sample time causes an error during model compilation. For more information, seeSimulink.BusElement objects no longer support the SampleTime property.

  5. Complexity

  6. Dimensions mode

  7. Minimum

  8. Maximum

  9. Units

  10. Description

'object'format saves theBusobject definitions as arrays. The function uses array indexing to access elements of the array and dot notation to assign property values.

Data dictionary, specified as aSimulink.data.Dictionaryobject. Before you use this argument, represent the dictionary with aSimulink.data.Dictionaryobject by using, for example, theSimulink.data.dictionary.createorSimulink.data.dictionary.openfunction.

Ifscopeis empty, the function uses the MATLAB base workspace as the source of theBusobjects.

Output Arguments

collapse all

Bus object information, returned as a structure array.

When you specifyblocks, each element of thebusInfostructure array corresponds to one block and contains these fields:

  • block— Handle of the block

  • busName— Name of theBusobject associated with the block

When you specify astruct,busInfostructure contains these fields:

  • block——空矩阵([])

  • busName— Name of theBusobject that corresponds to the structure

Version History

Introduced before R2006a

expand all

Errors starting in R2020b