Main Content

View Sparkline Plots of Simulation Data

This example shows the basic workflow for viewing sparkline plots of logged simulation data for selected blocks and variables directly on the model canvas. Before viewing sparkline plots, you must enable data logging for the whole model, or at least for those blocks where you want to display the data, and run the simulation.

  1. Open the Permanent Magnet DC Motor example model. At the MATLAB® command prompt, enter:

    openExample('simscape/PermanentMagnetDCMotorExample')

    This example model has data logging enabled for the whole model.

  2. Double-click the DC Motor subsystem to open it.

  3. Simulate the model.

  4. To enable display of the sparkline plots on the model canvas, select any Simscape™ block in the model, for example, the Rotational Electromechanical Converter block. On the Simscape Block tab at the top of the model window, under Review Results, click Sparkline Plot > Enable Sparkline Plots. This action adds the check mark next to the Enable Sparkline Plots option, and you can start selecting blocks to display sparkline plots of logged data for their variables. Repeatedly clicking a block toggles the display of its sparkline plots on and off.

  5. Click the Rotational Electromechanical Converter block again, to toggle its sparkline plots on. Sparkline plots of the first three variables available for this block are displayed on the canvas, and the field below the plots shows that 5 more variables are available.

  6. To customize which plots are shown on the canvas, click the little wheel symbol in the field below the plots.

    This action displays a list of all the block variables available, with check marks next to the one currently plotted.

  7. Clear all the check marks and select the last variable, w, instead. Then click anywhere on the model canvas to close the variable selection box.

    As you hover over the field with the variable name on the canvas, it expands into a sparkline plot of logged simulation data for that variable.

    The plot display includes the minimum and maximum values, as well as time and value for the current cursor position.

  8. As you move your cursor past the right edge of the plot, the current value is replaced with the last value of the variable. Clicking or hovering over the arrow to the right of the sparkline plot opens an additional field underneath, which contains a link to the Simscape Results Explorer. When you click the icon, the Simscape Results Explorer window opens, displaying the corresponding plot in the right pane, with the appropriate node selected in the left pane.

Tips

  • If you select a block for which simulation data is not being logged, it displays No variables instead of the sparkline plots. Right-click the block, select Simscape > Log simulation data, and rerun the simulation.

  • To clear all plots and start again with a clean canvas, on the Simscape Block tab, click Sparkline Plot > Remove Sparklines. Then you can select more blocks and variables to display their sparkline plots.

  • Repeatedly selecting the Enable Sparkline Plots option toggles the ability to view the sparkline plots for the model on or off, as indicated by the check mark. When the check mark is on, repeatedly clicking a block toggles the display of its sparkline plots on and off.

Related Examples

More About