Main Content

Simulink.Bus.cellToObject

Create Simulink.Bus objects from cell array of bus information

Description

example

Simulink.Bus.cellToObject(C) creates Simulink.Bus objects in the MATLAB® base workspace from the cell array of bus information specified by C.

Simulink.Bus.cellToObject(C,scope) creates Simulink.Bus objects in the data dictionary specified by scope.

Examples

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 Simulink.Bus object contains, create an array of Simulink.BusElement objects or a cell array of the property values for the Simulink.BusElement objects.

When you define the elements in an array, 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";

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

elementsCellArray = {{'a',1,'double','real','Sample'}; ...
    {'b',1,'double','real','Sample','Fixed',-3,3,'m',''}};

In this example, elementsArray and elementsCellArray create identical Simulink.BusElement objects.

To create multiple Simulink.Bus objects at once, create a cell array with two subordinate cell arrays that define the Simulink.Bus objects. For each Simulink.Bus object, specify the bus name, header file, description, data scope, alignment, preservation of element dimensions, and elements.

busCell = {{'BusObjArray','','','Auto','-1','0',elementsArray}, ...
    {'BusObjCellArray','','','Auto','-1','0',elementsCellArray}};

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

Simulink.Bus.cellToObject(busCell)

To compare the Simulink.Bus objects, open the Type Editor.

typeeditor

BusObjArray and BusObjCellArray in the Type Editor

The Simulink.Bus objects are identical other than their names.

Input Arguments

collapse all

Bus information, specified as a cell array of cell arrays. Each subordinate cell array must contain this Simulink.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 must contain arrays or cell arrays with this information for each of the Simulink.BusElement objects that the Simulink.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

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

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

Tips

The inverse function is Simulink.Bus.objectToCell.

Version History

Introduced before R2006a

expand all