Main Content


Convert cell array containing bus information to Simulink.Bus objects



Simulink.Bus.cellToObject(busCell) creates a set of Simulink.Bus objects in the MATLAB® base workspace from a cell array of bus information.

Simulink.Bus.cellToObject(busCell,scope) creates a set of Simulink.Bus objects in the data dictionary specified by scope from a cell array of bus information.


collapse all

This example shows how to create and use a cell array to generate Simulink.Bus objects in the base workspace.

To define the elements that the Bus object contains, create an array of Simulink.BusElement objects or a cell array of the property values for the BusElement objects.

When you define the elements in an array of BusElement objects, you must specify the values that differ from the default.

elementsArray(1) = Simulink.BusElement;

elementsArray(2) = Simulink.BusElement;
elementsArray(2).Name = 'b';
elementsArray(2).Min = -3;
elementsArray(2).Max = 3;
elementsArray(2).Unit = 'm';
elementsArray(2).Description = 'b is distance from the origin.';

When you define the elements in a cell array of property values, you must specify the element name, dimensions, data type, complexity, and sampling mode. You can also specify the dimensions mode, minimum, maximum, units, and description.

elementsCellArray = {{'a',1,'double',-1,'real','Sample'}; ...
            'Fixed',-3,3,'m','b is distance from the origin'}};

In this example, elementsArray and elementsCellArray create the same BusElement objects in the Bus objects.

Create a cell array with two subordinate cell arrays that define Bus objects. For each Bus object, specify the bus name, header file, description, data scope, alignment, preserve element dimensions, and elements. For the first Bus object, specify the elements using elementsArray. For the second Bus object, specify the elements using elementsCellArray.

busCells = { ...
        { ...
            'myBusObjArray', ...
            'MyHeader.h', ...
            'My description', ...
            'Exported', ...
            '-1', ...
            '0', ...
        }, ...
        { ...
            'myBusObjCellArray', ...
            'MyHeader.h', ...
            'My description', ...
            'Exported', ...
            '-1', ...
            '0', ...
        }, ...

Generate the Bus objects in the base workspace from the cell array of cell arrays.


Compare the generated Bus objects in the Type Editor.


The Bus objects are identical other than their names.

Input Arguments

collapse all

Bus object information, specified as a cell array of cell arrays. Each subordinate cell array must contain this Bus object information:

  1. Bus name

  2. Header file

  3. Description

  4. Data scope

  5. Alignment

  6. Preserve Element Dimensions

  7. Elements

The elements field is a cell array that contains this information for each of the Simulink.BusElement objects that the Bus object references:

The elements field must contain arrays or cell arrays with this information for each of the Simulink.BusElement objects that the Bus object references:

  1. Element name

  2. Dimensions

  3. Data type

  4. Sample time (optional) — If you specify a sample time, specify an inherited sample time (-1). A noninherited sample time causes an error during model compilation. For more information, see Simulink.BusElement objects no longer support the SampleTime property.

  5. Complexity

  6. Sampling mode

The elements field arrays or cell arrays can also contain this information:

  1. Dimensions mode

  2. Minimum

  3. Maximum

  4. Units

  5. Description

Example: Simulink.Bus.cellToObject(busCell);

Data dictionary, specified as a object. Before you use this argument, represent the dictionary with a object by using, for example, the or function.

If scope is empty, the function uses the MATLAB base workspace as the source of the Bus objects.

Example: Simulink.Bus.cellToObject(busCell,dataDictionaryObject);


The inverse function is Simulink.Bus.objectToCell.

Version History

Introduced before R2006a

expand all