Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Simulink.Bus.createObject

Create bus objects from blocks or MATLAB structures

Syntax

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

Description

example

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.

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

clear;
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;

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

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

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.

Simulink.Bus.cellToObject(busCell)

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

Tips

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?