Main Content

Simulink.Bus.save

Save Simulink.Bus objects in function

Description

example

Simulink.Bus.save(fileName) saves all Simulink.Bus objects from the MATLAB® base workspace in a function. The generated function defines object properties in a cell array of cell arrays, then creates the Bus objects by calling Simulink.Bus.cellToObject.

example

Simulink.Bus.save(fileName,format) saves the Bus objects in a function with the specified format. The function can define object properties using cell arrays or arrays.

example

Simulink.Bus.save(fileName,format,busNames) saves only the specified Bus objects in a function.

Simulink.Bus.save(fileName,format,busNames,scope) saves the Bus objects from the data dictionary specified by scope in a function.

Examples

collapse all

Use the Simulink.Bus.save function to save a Bus object.

Create a cell array of Bus object information.

busCell = { ...
        { ...
            'myBusObj', ...
            'MyHeader.h', ...
            'My description', ...
            'Exported', ...
            '-1', ...
            {{'a',1,'double','real','Sample'}; ...
            {'b',1,'double','real','Sample', ...
            'Fixed',-3,3,'m','b is distance from the origin'}}, ...
        } ...
        { ...
            'myBusObj1', ...
            'MyHeader1.h', ...
            'My description', ...
            'Exported', ...
            '-1', ...
            {{'c',1,'double','real','Sample'}; ...
            {'d',1,'double','real','Sample'}}, ...
        } ...
    };

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

Simulink.Bus.cellToObject(busCell);

Save the Bus objects in a function, using the default format.

Simulink.Bus.save('BusObjectFunctionCellFormat');

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

Simulink.Bus.save('BusObjectFunctionObjectFormat','object');

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

Simulink.Bus.save('BusObjectFunctionSubset','cell',{'myBusObj'});

Input Arguments

collapse all

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

Example: Simulink.Bus.save('BusObjectFunction');

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 Bus object definitions in a cell array of cell arrays and creates the Bus objects by calling Simulink.Bus.cellToObject. Each subordinate cell array represents a Bus object and contains these properties:

  1. Bus name

  2. Header file

  3. Description

  4. Data scope

  5. Alignment

  6. Elements

The elements field is a cell array that contains 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 — 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. Dimensions mode

  7. Minimum

  8. Maximum

  9. Units

  10. Description

The 'object' format saves the Bus object definitions as arrays. The function uses array indexing to access elements of the array and dot notation to assign property values. For more information, see Array Indexing and Access to Property Values.

Example: Simulink.Bus.save('BusObjectFunction','object');

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

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

When you specify an empty cell array, all Bus objects are saved. Use an empty cell array to save all Bus objects in the data dictionary specified by scope.

Example: Simulink.Bus.save('BusObjectFunction','cell',{'myBusObj'});

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

Example: Simulink.Bus.save('BusObjectFunction','cell',{},dataDictionaryObject);

Compatibility Considerations

expand all

Errors starting in R2020b

Introduced before R2006a