Simulation with Data Import and Signal Inspection

Data Import and Logging Workflow

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:

  1. Import signal data from a Microsoft® Excel® spreadsheet into a Signal Builder block. See Import Signal Data.

  2. Simulate the model after enabling the logging of output signals during simulation. See Simulate Model.

  3. View and compare the output signals in the Simulation Data Inspector.
    See Compare Signals.

  4. Create, print, and save a plot from the Simulation Data Inspector.
    See Create, Save, and Print a Figure.

Example Used in this Tutorial

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.

Import Signal Data

Prepare Signal Builder Block

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.

  1. In the MATLAB® Command Window, enter:


    The example model with a Signal Builder block opens in a Simulink editor window.

  2. Double-click the Signal Builder block. A Signal Builder window opens and displays one data group with an Amplitude signal.

  3. From the Signal Builder menu, select Group > Copy. A second group named Group 2 appears in the Active Group drop-down list.

  4. 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.

Importing Data from Excel Spreadsheets

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.

  1. 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.

  2. Select the Select All check box.

  3. 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.

  4. Click the Confirm Selection button.

  5. 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.

  6. Click OK.

Displaying Input Data

After you import data from the Excel file, you can view the input signals in the Signal Builder window.

  1. In the Signal Builder window, display the Ramp Input group.

  2. 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.

  3. From the menu, select Axes > Set T Display Limits. In the Set time range dialog box, enter 2.5 for the maximum time.

  4. Repeat Step 3 to set the time range for the other input group.

  5. 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.

Simulate Model

Configuring the Model to Log Output Signals

To log and display your output, you must configure the data import and export parameters of the model.

  1. In the model window, select Simulation > Model Configuration Parameters. The Configuration Parameters dialog box opens to the Solver pane.

  2. In the left pane, select Data Import/Export.

  3. Select the following check boxes:

    • Time

    • Output

    • Signal logging

    • Record logged workspace data in Simulation Data Inspector

  4. Set the Configuration Parameters > Data Import/Export > Format parameter to Structure with time.

  5. Click OK.

Running the Simulation

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.

  1. In the Signal Builder toolbar, click the Run all button.

    Simulink runs the model simulation from 0.0 to 2.00 seconds for the Impulse Input data and then runs again for the Ramp Input amplitude data. The Simulation Data Inspector opens.

  2. Select the signals that you want to display.

    If you select the Input Signal and the Triggered Counter signal for Run 1, two lines appear in the Simulation Data Inspector plot.

    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.

Compare Signals

The Simulation Data Inspector allows you to quickly compare and inspect signals between different runs.

  1. In the Simulation Data Inspector window, click the Compare tab. By default, Run 1 and Run 2 are selected for comparison in the Baseline and Compare To drop-down lists.

  2. Click the Compare Runs button to compare each signal between the Baseline and Compare To runs. The Simulation Data Inspector switches to the Comparisons pane to show all of the signal comparisons.

  3. Select the Enable Counter radio button to plot the comparison.

    Inspect the signals. The top plot contains the two individual signals from each run. The bottom plot represents the difference between the two signals and the tolerance value. In this case, the tolerance is zero. Since the difference is greater than zero, the comparison is not within the tolerance.

To work with your plots as figures, see Create, Save, and Print a Figure.

Create, Save, and Print a Figure

Creating a Figure from a Plot

You can create a figure from your Simulation Data Inspector plot to print or save to your computer.

  1. In the Simulation Data Inspector, click on the plot from which you want to create a figure.

  2. On the Compare tab, click Send to Figure.

    A MATLAB figure window opens with the selected signals.

Saving and Printing a Figure

To save your figure to your computer:

  1. In the Figure window, select File > Save as. A Save as dialog box opens.

  2. Navigate to the folder where you want to save your figure.

  3. In the File name field, enter the name of your figure.

  4. 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.

  5. Click the Save button.

  6. To print the figure, select File > Print.

Was this topic helpful?