Simulink.Bus.cellToObject
Convert cell array containing bus information to Simulink.Bus
objects
Description
Simulink.Bus.cellToObject(
creates a set of busCell
)Simulink.Bus
objects in the MATLAB® base workspace from a cell array of bus information.
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 Bus
object contains, create an array of Simulink.BusElement
objects or a cell array of the property values for the BusElement
objects.
When you define the elements in an array of BusElement
objects, you must 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'; elementsArray(2).Description = 'b is distance from the origin.';
When you define the elements in a cell array of property values, you must specify the element name, dimensions, data type, complexity, and sampling mode. You can also specify the dimensions mode, minimum, maximum, units, and description.
elementsCellArray = {{'a',1,'double',-1,'real','Sample'}; ... {'b',1,'double','real','Sample',... 'Fixed',-3,3,'m','b is distance from the origin'}};
In this example, elementsArray
and elementsCellArray
create the same BusElement
objects in the Bus
objects.
Create a cell array with two subordinate cell arrays that define Bus
objects. For each Bus
object, specify the bus name, header file, description, data scope, alignment, preserve element dimensions, and elements. For the first Bus
object, specify the elements using elementsArray
. For the second Bus
object, specify the elements using elementsCellArray
.
busCells = { ... { ... 'myBusObjArray', ... 'MyHeader.h', ... 'My description', ... 'Exported', ... '-1', ... '0', ... elementsArray,... }, ... { ... 'myBusObjCellArray', ... 'MyHeader.h', ... 'My description', ... 'Exported', ... '-1', ... '0', ... elementsCellArray,... }, ... };
Generate the Bus
objects in the base workspace from the cell array of cell arrays.
Simulink.Bus.cellToObject(busCells)
Compare the generated Bus
objects in the Type Editor.
typeeditor
The Bus
objects are identical other than their names.
Input Arguments
busCell
— Simulink.Bus object information
cell array of cell arrays
Bus
object information, specified as a cell array of cell
arrays. Each subordinate cell array must contain this Bus
object information:
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 Bus
object references:
The elements field must contain arrays or cell arrays with this
information for each of the Simulink.BusElement
objects
that the 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
Example: Simulink.Bus.cellToObject(busCell);
scope
— Data dictionary to contain Simulink.Bus objects
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 Bus
objects.
Example: Simulink.Bus.cellToObject(busCell,dataDictionaryObject);
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
In R2016b, the SamplingMode
property of Simulink.BusElement
objects was removed. Scripts that use the SamplingMode
property of Simulink.BusElement
objects continue to work. Simulink.Bus.cellToObject
continues to require the SamplingMode
field and Simulink.Bus.objectToCell
continues to include the sampling mode in the output cell arrays.
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.
See Also
Objects
Functions
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
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)