|On this page…|
Simulink® provides two features to import data and view simulation results: the Signal Builder block and the Simulation Data Inspector. Use the Signal Builder block to import input signals into your model. The Simulation Data Inspector allows you to view model output signals and compare them.
A typical workflow includes the following steps:
Import signal data from a Microsoft® Excel® spreadsheet into a Signal Builder block. See Import Signal Data.
Simulate the model after enabling the logging of output signals during simulation. See Simulate Model.
View and compare the output signals in the Simulation
See Compare Signals.
Create, print, and save a plot from the Simulation
See Create, Save, and Print a Figure.
sldemo_2counters is a Simulink model that includes a Signal Builder block and two subsystems. Each subsystem is a counter circuit.
Enabled Subsystem — Increments the counter when the subsystem is enabled and subsequently retains its output while the subsystem is disabled. Because the Enable port is configured to reset states when enabling, the counter returns to zero when the subsystem is re-enabled.
Triggered Subsystem — Increments the counter for each rising edge of the control signal.
ex_signaldata.xls is a Microsoft Excel file. It contains two sets of input data on two sheets. The first set of input data is a square wave to test the model response to an impulse. The second set of input data is a triangular wave to test the model response to a ramp signal.
The example Excel spreadsheet contains two sets of input data on two separate sheets. Because the Signal Builder block imports separate sheets into separate groups, you need to create a second group.
In the MATLAB® Command Window, enter:
The example model with a Signal Builder block opens in a Simulink editor window.
Double-click the Signal Builder block. A Signal Builder window opens and displays one data group with an Amplitude signal.
From the Signal Builder menu, select Group > Copy. A second group named Group 2 appears in the Active Group drop-down list.
Select Group > Rename, and enter more meaningful names that describe the input data. For example, rename Group 1 and Group 2 to Impulse Input and Ramp Input.
Simulink saves data imported from an Excel file using a Signal Builder block with the model and loads the data into memory when you open the model. If you have large sets of data, consider using a MAT-file with the Inport block.
From the Signal Builder menu, select File > Import from File. In the Import File dialog box, click the Browse button, find the folder matlabroot\help\toolbox\simulink\examples, and select ex_signaldata.xls.
The Data to Import section of the Import File dialog box displays the Excel file name with a list of sheets in the file.
Select the Select All check box.
From the Placement for Selected Data list, select Append selected signals to different groups (in order). Signal Builder converts the data on each sheet into a group.
Click the Confirm Selection button.
Review the Status History pane.
The Status History section includes the following information:
The data import is successful.
The Signal Builder block recognizes one signal per sheet.
The Signal Builder block recognizes the signal name, Amplitude, from the Excel spreadsheet.
After you import data from the Excel file, you can view the input signals in the Signal Builder window.
In the Signal Builder window, display the Ramp Input group.
Select the signal labeled Amplitude, and then select Edit > Delete. The original Amplitude signals are removed from both the Impulse Input and Ramp Input groups.
From the menu, select Axes > Set T Display Limits. In the Set time range dialog box, enter 2.5 for the maximum time.
Repeat Step 3 to set the time range for the other input group.
Select File > Save.
Your signal groups should look like the following. Keep this window open.
If you don't see the wave in either group, double-click Amplitude1 in the lower right box.
Note: After deleting the original Amplitude signal from the Signal Builder, you may need to reconnect the Input Signal line to the Signal Builder block in your model.
You can now set up the model to log output signals and simulate. See Simulate Model.
To log and display your output, you must configure the data import and export parameters of the model.
In the model window, select Simulation > Model Configuration Parameters. The Configuration Parameters dialog box opens to the Solver pane.
In the left pane, select Data Import/Export.
Select the following check boxes:
Record and inspect simulation output
Set the Configuration Parameters > Data Import/Export > Format parameter to Structure with time.
You can run simulations from the Signal Builder window. Select the input you want to run with this model or run separate simulations with each of the defined inputs.
In the Signal Builder toolbar, click the Run all button.
Simulink runs the model simulation from 0.0 s to 2.00 s for the Impulse Input data and then runs again for the Ramp Input amplitude data. The Simulation Data Inspector opens.
Select the signals that you want to display.
If you select the Input Signal and the Triggered Counter signal for Run 1, two line plots appear in the right pane of the Simulation Data Inspector window.
Note: If you do not see data in the Simulation Data Inspector window, you may need to reconnect the Input Signal line to the Signal Builder block in your model, and run the simulation again.
Now, you can inspect the results further. See Compare Signals.
The Simulation Data Inspector allows you to quickly compare two signals from the same or different runs.
In the Simulation Data Inspector window, click the Compare Signals tab. By default, five columns are displayed, including Sig 1 and Sig 2.
In the Sig 1 column, for Run 1, select the Enable Counter signal. Likewise, in the Sig 2 column, for Run 2, select the Enable Counter signal.
Inspect the signals. In the top pane, the plot contains the two individual signals. In the bottom pane, a single plot represents the difference of these two signals.
To work with your plots as figures, see Create, Save, and Print a Figure.
You can create a figure from your Data Inspector plot, to print or save to your computer.
In the Simulation Data Inspector window, select the Plot options button in the upper right of a signal plot. From the submenu, select Plot in new figure.
A MATLAB figure window opens with the selected signals.
To save your figure to your computer:
In the Figures window, select File > Save as. A Save as dialog box opens.
Navigate to the folder where you want to save your figure.
In the File name field, enter the name of your figure.
From the Save as type menu, select a file format. If you keep the default, MATLAB Figure (*.fig), then when you reopen the figure, the model also opens.
Click the Save button.
To print the figure, select File > Print.