Skip to Main Content Skip to Search
Product Documentation

Simulink.Bus.createMATLABStruct - Package: Simulink.Bus

Create MATLAB structure with same shape and attributes as bus signal

Syntax

mStruct = Simulink.Bus.createMATLABStruct('busObjectName', partialStruct)
mStruct = Simulink.Bus.createMATLABStruct(portHandle, partialStruct)
cellArrayOfStructures = Simulink.Bus.createMATLABStruct(arrayOfPortHandles, cellArrayOfPartialStructs)

Description

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.

Tips

Input Arguments

'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

  • The first partial structure in the cell array applies to the first port handle to produce the first element of the cell array of the full structure.

  • Specify an equal number of port handles and partial structures.

  • Use port handles of input or output ports. Do not include port handles of action, trigger, or enable ports.

  • If you use only one port and one partial structure, you do not need to specify the port handle in an array or in the structure in the cell array.

Output Arguments

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

Examples

MATLAB Structure From Bus Object

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.

MATLAB Structure From Bus Port and Partial Structure

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);

See Also

Bus Assignment | Bus Creator | Bus to Vector | Simulink.Bus | Simulink.Bus.cellToObject | Simulink.Bus.createObject | Simulink.Bus.objectToCell | Simulink.Bus.save | Simulink.BusElement

Tutorials

  


Related Products & Applications

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