Load Data Using Playback Block
This example shows how to use the Playback block to load data from a file. In this example you:
Add data to the Playback block.
Assign signal data to ports.
Configure port parameters.
Run a simulation to load the data into the model.
The model consists of a Playback block connected to a Record Block. The Playback block loads external data into the model. The Record block logs the data output by the Playback block. You can use the Playback block to visualize data before loading it into the model, and you can use the Record block to visualize the logged signal data.
Add Data to Playback Block
Open the model
PlaybackRecord.slx, which contains an empty Playback block connected to a Record block. You can use the Playback block to load data from the workspace, a file, and the Simulation Data Inspector.
To add data, double-click the Playback block. The Playback block presents three options to add data: add a workspace variable, add a file, or open the Add Signals dialog box for more options, such as adding runs from the Simulation Data Inspector. Suppose you collect data in the field and save the data to a Microsoft Excel® file named
TempDataFile.xlsx, which contains two sets of indoor and outdoor temperature data. To add this signal data to the Playback block, select the file
TempDataFile.xlsx from the file drop-down list.
Visualize Signal Data Before Loading to Model
You can visually inspect the data in a sparkline plot before loading signals into the model. If you do not want to view a sparkline for a signal, you can clear the check box next to the signal name. Clearing the check box affects only which signals are plotted in the visualization, not which signals are loaded into the model during simulation.
Assign Signals to Ports
You can set the number of ports on the Playback block and change which signal each port loads. The number of signals you add to the Playback block does not need to equal the number of ports. When you want to add a signal to the Playback block without loading the signal data into the model, do not assign the signal to a port. For example, to load only one set of temperature data, you can change the number of ports and the port assignments.
You can assign and unassign signals to ports using the Port column in the signals table:
Click the Port column in the same row as the signal you want to assign or unassign to a port.
Select the port number from the drop-down list. To assign a signal to no port, choose Unassigned.
If you unassign a signal from a port, the Unassign Port dialog box prompts you to choose to delete the port or keep the port with no signal assigned.
To load the first measurement of indoor and outdoor temperature into the model, assign the
TempIndoor_Run1 signal to port 1 and the
TempOutdoor_Run1 signal to port 2. Changing port assignments allows you to control the signal data the Playback block loads into the model.
To load a set of indoor and outdoor temperature data, the Playback block needs only two ports. One port loads the indoor temperature data. The second port loads the outdoor temperature data. You can use the Port Editor to add or delete ports.
To delete a port using the Port Editor:
On the Simulation tab, under Port, click Port Editor.
Select the row of the port you want to delete.
Click Delete Port.
To delete port 3 and port 4, you can use the Port Editor, or you can unassign the signals from port 3 and port 4 in the signal table. Then, in the Unassign Port dialog box, select Delete Port. Notice that all four signals are visible in the sparkline visualization even though only the
TempOutdoor_run1 signals are loaded into the model.
Specify Port Parameters
You can change port properties using the Port Editor. By default, port properties are inherited from the signal. The Microsoft Excel® file format does not include sample time in the signal metadata, so the sample time for the signals added from the Excel file is inherited as continuous from the model. However, the physical measurement data is discrete. The indoor temperature data has a sample time of
0.2. The outdoor temperature data has a sample time of
0.1. In the Sample Time column of the Port Editor, specify the sample time for the
TempIndoor_run1 signal as
0.2 and the
TempOutdoor_run1 signal as
0.1 so the output signal reflects the discrete sample time with which the data was collected.
You can also use the Port Editor to perform a unit conversion. The temperature data was measured in degrees Fahrenheit. You can use the Units port property to convert the data to Celsius. In the Units column of the Port Editor, change the units from
Changing the units on the port does not change the visualization in the Playback block because the signals added to the Playback block are in degrees Fahrenheit. The conversion to Celsius occurs when the data leaves the Playback block and enters the model.
The Playback block loads data into the model when you run a simulation. Only the signals or messages assigned to ports are loaded into the model.
Add data into the model:
Click Up To Parent to return to the model.
Connect the second port of the Playback block to the Record block.
Name the signals in the model so each signal is easy to identify in the Record block.
Run the simulation.
Double-click the Record block to view the data loaded by the Playback block.
You can use Information Overlays to view port units and color code the model based on sample times.
To display signal units in the model, on the Debug tab, in the Diagnostics section, select Information Overlays > Units.
To enable color coding, on the Debug tab, in the Diagnostics section, select Information Overlays > Colors. For more information, see View Sample Time Information.
Visualize Logged Signal Data
To visualize the logged signal data, you can double-click the Record block. In the Record block sparkline visualization, you can see that the Playback block produced discrete signals and converted the temperature values to Celsius.
Because only the first measurements of indoor and outdoor temperature data are assigned to ports, the
TempOutdoor_run1 signals are the only ones loaded into the model. You can choose to assign different data to the existing ports or add more ports to load multiple sets of indoor and outdoor temperature data.