Load Input Data for Bus Using In Bus Element Blocks - MATLAB & Simulink (original) (raw)

This example shows how to use In Bus Element blocks to load external input data for bus elements. Using In Bus Element blocks allows flexibility in the design and implementation of external interfaces for buses.

Open and Inspect Model

Open the model LoadInBusElement. The model has one port named InBus that is defined using three In Bus Element blocks. Each In Bus Element block connects to a Display block. The Dashboard Scope block below each In Bus Element and Display block pair plots the signal that the In Bus Element block creates from the loaded data.

mdl = "LoadInBusElement"; open_system(mdl)

The model LoadInBusElement.

The label of each In Bus Element block indicates the name of the port and the bus element the block selects. From left to right, the In Bus Element blocks in the model have these labels:

The Input parameter for the model specifies the external input data for top-level input ports to load during simulation. To check the current value of the Input parameter for the model LoadInBusElement:

  1. Open the Configuration Parameters dialog box. In the Simulink® Toolstrip, on the Modeling tab, click Model Settings.
  2. On the Data Import/Export pane, check that the Input parameter is selected and configured to load data from the variable named inbusdata.

The variable inbusdata maps to the port named InBus according to the Port Number defined in the In Bus Element dialog box.

Alternatively, programmatically check the model configuration by using the get_param function to check the values of the LoadExternalInput and ExternalInputData parameters.

get_param(mdl,"LoadExternalInput")

get_param(mdl,"ExternalInput")

Create External Input Data for Bus

Specify external input data for a bus as a structure with hierarchy and field names that match the hierarchy and element names of the bus. Specify the data for each leaf element as a timeseries object, a timetable that contains data in only one column, or a matlab.io.datastore.SimulationDatastore object. This example creates the structure using a timetable for each bus element.

Create a column vector of time values that start at 0 and end at 10 with a step size of 1.

Use the time vector to create data that represents a sine wave, a constant, and a line.

sinedata = sin(t); constdata = 3*ones(11,1); linedata = linspace(0,10,11)';

To create a timetable, the input values you provide must be a duration vector. Use the seconds function to convert the time vector to a duration vector with units of seconds.

Create a timetable object to contain the data for each type of signal.

sine = timetable(t,sinedata); const = timetable(t,constdata); line = timetable(t,linedata);

Construct the structure inbusdata that provides the input data for the port in the model. The structure field names must match the bus element names.

inbusdata.a.x = const; inbusdata.a.y = line; inbusdata.b = sine;

Fully Specify Input Data

The data in the structure inbusdata fully specifies data for the signal selected by the In Bus Element blocks in the model. The structure contains data for:

Simulate the model and observe the signals on the Dashboard Scope blocks. In the Simulink Toolstrip, on the Simulation tab, click Run.

Alternatively, run the simulation using the sim function.

The Dashboard Scope blocks in the model display the In Bus Element block output signals from the simulation.

The plots in the Dashboard Scope blocks show that each In Bus Element block produces a signal in the model that matches the data specified in the structure inbusdata.

Partially Specify Input Data

When you use In Bus Element blocks to select bus elements, you can partially specify external input data for the bus. A structure partially specifies input data for a bus if the structure does not contain a signal for:

The In Bus Element block produces ground values throughout the simulation selected elements that do not have data in the structure.

For example, edit the label for the In Bus Element block that selects element a.y so that the block selects element a.z. Alternatively, use the set_param function to specify the element to select.

blkpth = mdl + "/Bus Element In1"; set_param(blkpth,Element="a.z")

Simulate the model without modifying the structure. The structure that maps to the port named InBus partially specifies data for the model because the structure does not contain data for an element named z inside the nested bus named a.

The Dashboard Scope blocks in the model display the In Bus Element block output signals from the simulation.

The plots of the Dashboard Scope blocks show that:

Revert the change to the In Bus Element block that selects element a.z so that the block selects element a.y.

set_param(blkpth,Element="a.y")

Overspecify Input Data

When you use In Bus Element blocks to select bus elements, you can overspecify external input data for the bus. A structure overspecifies input data for a bus if the structure contains data for bus elements that no In Bus Element blocks associated with the top-level input port select.

For example, edit the label for the In Bus Element block that selects the element a.y so the block selects the element b. Alternatively, use the set_param function to specify the element to select.

set_param(blkpth,Element="b")

Simulate the model without modifying the structure. The structure that maps to the port named InBus overspecifies the input data for the port because none of the In Bus Element blocks selects element a.y. The simulation runs without issuing any diagnostics.

The Dashboard Scope blocks in the model display the In Bus Element block output signals from the simulation.

The plots of the Dashboard Scope blocks show that:

See Also

Blocks

Objects

Functions

Topics