Main Content

Save Simulink.Bus object definitions in function


example saves definitions of all Simulink.Bus objects in the MATLAB® base workspace to a function.

example,fileFormat), where fileFormat is "object", saves the Simulink.Bus object definitions using arrays. The "object" format makes the function easier to read. The default for fileFormat is "cell", which uses cell arrays and is more compact.

example,fileFormat,busNames) saves definitions of only the Simulink.Bus objects specified by busNames.,fileFormat,busNames,scope) saves the Simulink.Bus object definitions from the data dictionary specified by scope.


collapse all

When you create Simulink.Bus objects, save the Simulink.Bus object definitions for future use. To create functions that re-create the Simulink.Bus objects in the base workspace, use the function.

Suppose you create Simulink.Bus objects from the Bus Creator block named Bus Creator1 in the model named BusHierarchy.

mdl = "BusHierarchy";
block = "BusHierarchy/Bus Creator1";
busInfo = Simulink.Bus.createObject(mdl,block);

The objects named TopBus and NestedBus are in the base workspace.

To save the object definitions in a function for future use, use the function.

file1 = "DefaultFunction";;

By default, the function uses the "cell" format. For example, the Chirp element is defined by a cell array.

{'Chirp', 1, 'double', 'real', 'Sample', 'Fixed', [], [], '', ''};

For a function that is formatted to be easier to read, specify the function format as "object".

file2 = "FormattedFunction";,"object");

In the "object" format, the Chirp element is defined by an array that uses dot notation to assign property values.

elems(1) = Simulink.BusElement;
elems(1).Name = 'Chirp';
elems(1).Dimensions = 1;
elems(1).DimensionsMode = 'Fixed';
elems(1).DataType = 'double';
elems(1).Complexity = 'real';
elems(1).Min = [];
elems(1).Max = [];
elems(1).DocUnits = '';
elems(1).Description = '';

To save only one of the Simulink.Bus objects in a function, specify the object name.

file3 = "PartialSaveFunction";,"object",{'NestedBus'});

The function defines only the NestedBus object.

Input Arguments

collapse all

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


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

The 'cell' format saves the Simulink.Bus object definitions in a cell array of cell arrays and creates the Simulink.Bus objects by calling Simulink.Bus.cellToObject. Each subordinate cell array represents a Simulink.Bus object and contains these properties:

  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 Simulink.Bus object 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, see Simulink.BusElement objects no longer support the SampleTime property.

  5. Complexity

  6. Sampling mode

  7. Dimensions mode

  8. Minimum

  9. Maximum

  10. Units

  11. Description

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


Simulink.Bus objects to save, specified as an empty cell array ({}) or a cell array of Simulink.Bus object names.

  • If you specify a cell array of Simulink.Bus object names, only the specified objects are saved.

  • If you specify an empty cell array, all the Simulink.Bus objects are saved.

Use an empty cell array to save all the Simulink.Bus objects from the data dictionary specified by scope.


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 Simulink.Bus objects.


Version History

Introduced before R2006a

expand all