During the modeling process, you run simulations to learn about the behavior of your model. To observe that behavior, view and plot signal values during and after a simulation. Some common modeling tasks that include simulations are:
Prototype — Quickly model a design and compare design alternatives.
Validate — Compare simulated data with functional requirements to validate that you built your model correctly.
Optimize — Compare simulated data between simulations to check if changes to your model remain within a specified design tolerance.
Verify — Compare simulated data from a model with measured data from the modeled system to verify that your model gives the correct answer.
In Simulink® you can view simulation data using several approaches. Some approaches display signal data during a simulation. Other approaches save signal data to the MATLAB® workspace where you can post process the data. Learn about each of these approaches so you can choose one suitable for your application.
When debugging a model to isolate a particular issue, a common task is to observe signal values at each time step during a simulation. To observe a signal value, right-click a signal line, and then select Show Value Label of Selected Port.
Displaying port values for a bus signal allows you to monitor the signal values at each time step during a simulation.
Scope blocks and scope viewers offer a way to visualize your simulation data over time. If you are prototyping a model design, you can attach signals to a Scope block, and then simulate your model to test and validate the design. Use the oscilloscope-like tools (triggers and measurements) available with a scope to debug your model.
A Scope block or scope viewer opens to a scope window where you can display and evaluate simulation data. In the Scope window, you can:
Select signals — Connect signal lines to a Scope block using input ports. Attach signals to a Floating Scope block using the signal selector tool that hierarchically displays all signals in a model.
View signals — Compare selected signals by grouping them on multiple displays.
Prototype and debug — Set triggers to capture events, use interactive cursors to measure signal values at various points, and review signal statistics such as maximum and mean values. Also, control simulations and step through simulations to validate a design.
Save signal data — Save signal data to the MATLAB workspace using a dataset object, array, or structure format.
Supported data types — All data types supported by Simulink including variable-size, fixed-point, sample-based, and frame-based signals.
For more information, see Scope Blocks and Scope Viewer Overview.
If you run your simulation more than once and want to inspect or compare signal data between simulations, then you can use the Simulation Data Inspector. You can stream and store signal data from the model and compare data between multiple simulations. For example, you can check to see if the difference between two signals is within a certain design tolerance. In the Simulation Data Inspector, you can:
View signals — Inspect signal data while your model is simulating.
Import data — Import time series data from MAT-files or the base workspace.
Compare signal data — Compare multiple simulations to check the difference between runs.
Export data and generate reports — Export plots and comparison data to share or archive results.
For more information, see Inspect Signal Data with Simulation Data Inspector.
Create an interactive display of controls and displays within your model diagram using blocks from the Dashboard library. Connect block parameters to control blocks (Knobs, Buttons, and Switches) and signals to displays blocks. (Scopes and Gauges).
While a simulation is running, you can change parameter values using the controls. Signal values are updated continuously in the displays.
For more information, see Tune and Visualize Your Model with Dashboard Blocks.
Use Outport blocks to save simulation data from the top-level of your model to the MATLAB workspace. Select and define the variables for saving data in the Data Import/Export pane of the Configuration Parameters dialog box. For example, select the Time and Output check boxes.
After running a simulation, you can use MATLAB plotting
commands to display the simulation results. The variables
the default variables returned by the solver after a simulation.
For more information, see Data Import/Export Pane.
Use To Workspace blocks to
save simulation data from anywhere in your model to the MATLAB workspace.
Store a time vector by connecting a Clock block to a To Workspace
block. You can also get a time vector using the
During a simulation, the blocks write data to an internal buffer.
When you pause the simulation or it reaches the end time, data is
written to the workspace and saved in the variables
For more information, see Data Import/Export Pane.
You can save simulation data to the MATLAB workspace without using blocks.
Select signals for logging. Right-click a signal line, select Properties, and then select the Log signal data check box.
Enable signal logging during a simulation. In the Data Import/Export pane of the Configuration Parameters dialog box, select the Signal logging check box and enter a variable name.
For more information, see Export Signal Data Using Signal Logging.