Load Input Data for a Bus Using In Bus Element Blocks

This example shows how to use In Bus Element blocks to load input data for a bus. Using In Bus Element blocks allows flexibility in the design and implementation of external interfaces for buses. You can use an In Bus Element block to load data for an element of a bus and to load data for an entire bus. You can also use multiple In Bus Element blocks to select the same bus element.

Open and Inspect the Model

Open the ex_load_inbuselement model.

open_system('ex_load_inbuselement.slx')

One or more In Bus Element blocks can define a port in a model. The ex_load_inbuselement model has one port, InBus, defined by three In Bus Element blocks. The label for each In Bus Element block indicates the bus element the block selects. The InBus port corresponds to a bus containing a nested bus, a, with signals x and y, and an individual signal, b.

Use the Input parameter on the Data Import/Export pane to specify workspace data to load as simulation input for the port in the model. The Input parameter for the ex_load_inbuselement model loads the variable struct1, which maps to the port according to the Port Number defined in the In Bus Element block dialog box.

Create Input Data

Ports that load bus data accept structures composed of individual timeseries, timetable, and matlab.io.datastore.SimulationDatastore objects. The hierarchy of the structure must match the hierarchy of the bus. Ports that use In Bus Element blocks to select bus elements allow partial specification and overspecification of data.

This example creates the structure using three timeseries signals that correspond to a sine wave, a line, and a constant.

time = linspace(0,10,11);
sineData = sin(time);
constData = 3*ones(11,1);
lineData = linspace(0,10,11);

tsSine = timeseries(sineData,time);
tsConst = timeseries(constData,time);
tsLine = timeseries(lineData,time);

Construct the structure, struct1, to provide the input data for the port in the model. The structure field names must match the bus element names.

struct1.a.x = tsConst;
struct1.a.y = tsLine;
struct1.b = tsSine;

Fully Specify Input Data

The data created in the previous section fully specifies data for the signals selected by the In Bus Element blocks in the model. Simulate the model and observe the signals on the Dashboard Scope blocks.

Partially Specify Input Data

When you use In Bus Element blocks to select bus elements, you can partially specify data using a structure that does not include one or more selected elements. Elements without data defined in the structure use ground signal values for simulation.

For example, edit the label for the In Bus Element block that selects element InBus.a.y so that the In Bus Element block selects InBus.a.z. The structure that maps to the InBus port does not contain a field for z in the nested structure, a. When you simulate the model, without modifying the structure, the Dashboard Scope shows ground for InBus.a.z.

Change the In Bus Element port block that selects InBus.a.z back to select InBus.a.y.

Overspecify Input Data

When you use In Bus Element blocks to select bus elements, you can overspecify data for the port. Overspecified input data contains signals that are not selected by any of the In Bus Element blocks in the model.

For example, change the label for the In Bus Element block that selects InBus.a.y to select InBus.b. Now, none of the In Bus Element blocks selects InBus.a.y, while the structure still contains the data for that element.

Simulate the model and observe the signals on the Dashboard Scope blocks.