Skip to content
Tutorials Center
My learning

Topics

Lesson 4 of 36 ยท Getting Started

Logging and Inspecting Simulink Results: To Workspace and Data Inspector

Learn how to log Simulink signals with To Workspace, signal logging and Outport blocks, read the sim output object, and compare runs in the Simulation Data Inspector.

A Scope is great for looking at a curve, but real work needs numbers: you want to compute a peak value, compare two designs or feed the data into MATLAB code. Simulink offers several ways to log signals during a run. This lesson explains each one, what ends up where, and how the Simulation Data Inspector (SDI) helps you compare runs.

Simulink is not available on this site, so MATLAB and Simulink code is shown as read-only text. A Python stand-in imitates logging so you can practice the analysis steps.

The four ways to get data out

Method How Where the data appears
To Workspace block Place the block (Sinks library) and name the variable out.<variable name>
Signal logging Select a line, then Simulation > Log Signals (or right-click > Log Selected Signals) out.logsout
Outport blocks at the top level Add Out1, Out2 out.yout
Scope data logging Scope settings > Logging > Log data to workspace a variable of your choice

Time values are always logged as out.tout when Time is checked under Model Settings > Data Import/Export.

The To Workspace block

Open the block dialog and set:

  • Variable name: for example speed.
  • Save format: Timeseries (recommended), Structure With Time, Structure or Array.
  • Sample time: -1 inherits from the input. A positive number logs at that rate only.
  • Limit data points to last: an optional memory limit.

After the run, with the default Single simulation output setting enabled, everything comes back as one Simulink.SimulationOutput object.

MATLAB
out = sim('first_model');           % run the model
t = out.speed.Time;                 % time vector
y = out.speed.Data;                 % values
fprintf("peak = %.3f\n", max(y));
plot(t, y); grid on

A timeseries stores the time vector and data in one object, so Time and Data always stay in step.

Signal logging

Signal logging does not need extra blocks. Select a line and click Log Signals on the Simulation tab; a small antenna-like badge appears. Because the signal name appears in the log, name your lines first. Afterwards:

MATLAB
out = sim('first_model');
sig = out.logsout.get('speed');     % a Simulink.SimulationData.Signal
values = sig.Values;                % timeseries

Logged signals can also be streamed straight to the Data Inspector while the model runs.

The Simulation Data Inspector

Open it from Simulation > Data Inspector or with Simulink.sdi.view in MATLAB. When Record is on (the default is to record logged signals), each run appears under Runs. In the Inspector you can:

  • Plot signals from any run and tile several plots;
  • Use Cursors and Sync to read values at the same time;
  • Select two runs (or signals) and Compare: it computes the difference and checks it against tolerances;
  • Save a session to a .mldatx file and reopen it later;
  • Export data to the base workspace.

Where does the data go?

To Workspace out.name
Signal logging out.logsout
Outports out.yout
Time out.tout

Everything returns in one output object.

1 / 2

Practice the analysis with a stand-in

The code below logs a signal into a timeseries-like record, then does what you would do in MATLAB with out.speed: compute the peak and settling time. It also compares two "runs" the way the Data Inspector's compare feature does.

Python Stand-in: logging a signal and analyzing it (Python)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Python Stand-in: compare two runs like the Data Inspector (Python)

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Good logging habits

  • Name every logged signal. Unnamed lines make logs hard to read and break scripts that look signals up by name.
  • Log only what you need. Logging huge vectors at tiny sample times fills memory; use Decimation or Limit data points.
  • Use Timeseries for To Workspace. Plain arrays lose the time vector.
  • Separate recording from viewing. A Scope slows a simulation slightly; closing it (or using logging only) speeds up long runs.

If you run many simulations in a loop, call Simulink.sdi.clear occasionally, or turn off Record in the Inspector, to stop session files growing without limit.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Where do logged signals appear when Single simulation output is on?

    With Single simulation output, sim returns one Simulink.SimulationOutput with tout, yout, logsout and To Workspace variables as fields.
  2. 2. Which To Workspace save format keeps the time vector together with the data?

    A timeseries object stores Time and Data together.
  3. 3. What is the main use of the Simulation Data Inspector?

    SDI plots signals from multiple runs and can compare them with tolerances.
  4. 4. Which command opens the Data Inspector from MATLAB?

    Simulink.sdi.view opens the Simulation Data Inspector.

Summary

  • Use To Workspace blocks, signal logging, Outport blocks or Scope logging to get data out of a model.
  • With default settings sim returns one output object holding tout, yout, logsout and your variables.
  • Prefer the Timeseries format and name every signal.
  • The Data Inspector overlays and compares runs, with tolerances and saved sessions.

Next: Simulink from MATLAB Scripts