Simulink.Bus.save
Save Simulink.Bus
object definitions in function
Syntax
Description
Simulink.Bus.save(
saves
definitions of all file
)Simulink.Bus
objects in the MATLAB® base workspace to a function.
Simulink.Bus.save(
,
where file
,fileFormat
)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 than the "object"
format.
Simulink.Bus.save(
saves definitions of only the file
,fileFormat
,busNames
)Simulink.Bus
objects specified by
busNames
.
Simulink.Bus.save(
saves the file
,fileFormat
,busNames
,scope
)Simulink.Bus
object definitions from the data dictionary
specified by scope
.
Examples
Save Simulink.Bus
Object Definitions
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 Simulink.Bus.save
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"; load_system(mdl) 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 Simulink.Bus.save
function.
file1 = "DefaultFunction";
Simulink.Bus.save(file1);
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"; Simulink.Bus.save(file2,"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"; Simulink.Bus.save(file3,"object",{'NestedBus'});
The function defines only the NestedBus
object.
Input Arguments
file
— Name of function to generate
character vector | string scalar
Name of function to generate, specified as a character vector or string scalar. The file name must be unique.
Example: Simulink.Bus.save("BusObjectFunction");
fileFormat
— Format of function to generate
"cell"
(default) | "object"
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:
Bus name
Header file
Description
Data scope
Alignment
Preserve element dimensions
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:
Element name
Dimensions
Data type
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.
Complexity
Sampling mode
Dimensions mode
Minimum
Maximum
Units
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.
Example: Simulink.Bus.save("BusObjectFunction","object");
busNames
— Simulink.Bus
objects to save
empty cell array | cell array of bus objects
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
.
Example: Simulink.Bus.save("BusObjectFunction","cell",{'myBusObj'});
scope
— Data dictionary
Simulink.data.Dictionary
object
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.
Example: Simulink.Bus.save("BusObjectFunction","cell",{},dataDictionaryObject);
Version History
Introduced before R2006aR2020b: Simulink.BusElement
objects no longer support the SampleTime
property
The SampleTime
property of Simulink.BusElement
objects is no longer supported.
BusElement
objects that specify a sample time cause an error during
compile. To remove the sample time specification from a BusElement
object,
set its SampleTime
to -1
.
Simulink.Bus.cellToObject
continues to accept cell arrays that
specify sample time for bus elements. Simulink.Bus.objectToCell
,
Simulink.Bus.save
, and Simulink.Bus.createObject
continue to return cell arrays or arrays that include the sample time when it is noninherited.
When the sample time is inherited (-1
), they omit it. Similarly, the
Type Editor and Model Explorer omit the sample time when it is
inherited.
To specify the sample time for an element of a bus, use the
SampleTime
block parameter of corresponding blocks. For example,
you can use In Bus Element, Out Bus Element, and Signal
Specification blocks to specify sample time.
R2016b: Simulink.BusElement
objects will no longer support the SamplingMode
property
The SamplingMode
property of Simulink.BusElement
objects has been removed. Scripts that use the SamplingMode
property of
Simulink.BusElement
objects continue to work. The
Simulink.Bus.cellToObject
function continues to require the
SamplingMode
field. The
Simulink.Bus.objectToCell
function continues to include the
sampling mode in the output cell arrays. When you save Simulink.Bus
object
definitions to functions that use cell arrays, the cell arrays continue to include the
sampling mode.
In a future release, support for the SamplingMode
property will be
removed.
To specify whether a signal is sample-based or frame-based, define the sampling mode of input signals at the block level instead of at the signal level.
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)