| Contents | Index |
Create MATLAB structure with same shape and attributes as bus signal
mStruct = Simulink.Bus.createMATLABStruct('busObjectName', partialStruct)
mStruct = Simulink.Bus.createMATLABStruct(portHandle, partialStruct)
cellArrayOfStructures =
Simulink.Bus.createMATLABStruct(arrayOfPortHandles, cellArrayOfPartialStructs)
mStruct = Simulink.Bus.createMATLABStruct('busObjectName', partialStruct) creates a full structure for the Simulink.Bus object that you specify with 'busObjectName'. Optionally, use a partial structure (partialStruct) to specify a set of values for matching fields in the bus. If you specify a partialStruct, the values of the fields of the partial structure must have the same attributes as the corresponding fields in the bus object.
mStruct = Simulink.Bus.createMATLABStruct(portHandle, partialStruct) creates a full structure for the port that you associate with the bus. Specify that port with portHandle.
cellArrayOfStructures = Simulink.Bus.createMATLABStruct(arrayOfPortHandles, cellArrayOfPartialStructs) creates a cell array of full structures, for the port handles and partial structures that you specify. Using this syntax when you want to create initialization structures for multiple bus ports improves performance, compared to using separate Simulink.Bus.createMATLABStruct calls to create the structures.
If you use a port handle, the model must compile successfully before you use the Simulink.Bus.createMATLABStruct command.
The value of a field in the resulting structure is the ground value of the corresponding signal in the bus or bus object, unless you override that field in the resulting output structure by:
Specifying as an input argument a partial structure that assigns a value for that signal
Explicitly setting the value for a field in the structure after you create the structure
You can use the Bus Editor to invoke the Simulink.Bus.createMATLABStruct function. Use one of these approaches:
Select the File > Create a MATLAB structure menu item.
Select the bus object for which you want to create
a full MATLAB structure. Then, in the toolbar, click the Create
a MATLAB structure icon (
).
You can then edit the MATLAB structure in the MATLAB Editor and evaluate the code to create or update the values in this structure.
You can use the Simulink.Bus.createMATLABStruct function to specify the initial value of the output of a referenced model. For details, see the "Referenced Model: Setting Initial Value for Bus Output" section of the Detailed Workflow for Managing Data with Model Reference demo.
'busObjectName' |
Name of a bus object that is in the MATLAB base workspace |
partialStruct |
MATLAB structure or cell array of MATLAB structures Each field that you specify in partial structure must match the data attributes (such as type and dimension) of the corresponding bus element exactly. For details, see Match IC Structure Values to Corresponding Bus Element Data Characteristics. Optionally use partialStruct with the busObjectName or portHandle arguments. |
portHandle |
Handle to block input or output port The model that contains the port handle must compile successfully before you use the Simulink.Bus.createMATLABStruct command. |
arrayOfPortHandles |
Array of handles to block input or output ports |
cellArrayOfPartialStructs |
Cell array of MATLAB structures of subsets of initial condition values
|
mStruct |
MATLAB structure having the same shape and attributes as the specified bus signal |
cellArrayOfStructures |
MATLAB cell array of structures corresponding to cell array of port handles |
Create a MATLAB structure based on a bus object.
Open Simulink model and simulate it.
run([docroot '/toolbox/simulink/ug/examples/signals/busic_example.mdl']); sim('busic_example')
The simulated busic_example looks like this:

Create a MATLAB structure using the bus object Top, which the busic_example model loads.
mStruct = Simulink.Bus.createMATLABStruct('Top');
Set a value for the field of the structure that you created that corresponds to bus element A1 of bus A.
mStruct.A.A1 = 3;
Simulink sets the other fields in the structure to the ground value for the bus object Top.
You could specify mStruct as the initial condition structure for the Unit Delay block.
Create a MATLAB structure based on a port that connects to a bus signal. Use a partial structure to specify values for a subset of bus elements of the bus signal that connects to the port.
Open Simulink model.
run([docroot '/toolbox/simulink/ug/examples/signals/busic_example.mdl']); sim('busic_example')
The simulated busic_example looks like this:

Find the port handle for the Bus Creator block port that produces the Top bus signal.
ph = get_param('busic_example/TopBus','PortHandles');
Create a partial structure, which is a MATLAB structure that specifies values for a subset of bus elements for the bus signal created by the TopBus block.
PartialStructForK = struct('A',struct('A1',4),'B',3)
Bus element represented by structure fields Top.B and Top.A are at the same nesting level in the bus. You can use this partial structure to override the ground values for the B and A bus signal elements.
You can use a partial structure as an optional argument when creating a MATLAB structure from a bus object or from a bus port.
Create a MATLAB structure using the port handle (ph) for the TopBus block. Override the ground values for the A.A1 and B bus elements.
mStruct = Simulink.Bus.createMATLABStruct(ph, PartialStructForK);
Bus Assignment | Bus Creator | Bus to Vector | Simulink.Bus | Simulink.Bus.cellToObject | Simulink.Bus.createObject | Simulink.Bus.objectToCell | Simulink.Bus.save | Simulink.BusElement

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |