Simulink.Bus.cellToObject
Create Simulink.Bus
objects from cell array of bus
information
Description
Examples
Create Simulink.Bus
Object from Cell Array of Bus Information
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
The Simulink.Bus
objects are identical other than their names.
Input Arguments
C
— Bus information
cell array of cell arrays
Bus information, specified as a cell array of cell arrays. Each
subordinate cell array must contain this Simulink.Bus
object information:
Bus name
Header file
Description
Data scope
Alignment
Preserve element dimensions
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:
Element name
Dimensions
Data type
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.Complexity
Sampling mode
The elements field arrays or cell arrays can also contain this information:
Dimensions mode
Minimum
Maximum
Units
Description
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.
Tips
The inverse function is Simulink.Bus.objectToCell
.
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 Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)