| Products & Services | Industries | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Simulink |
| Contents | Index |
| Learn more about Simulink |
Logging signals refers to the process of saving signal values to the MATLAB workspace during simulation for later retrieval and postprocessing. Simulink allows you to log a signal by
Connecting the signal to a To Workspace block, Scope block, or viewer.
This method allows you to document in the diagram itself the workspace variables used to store signal data. Results are visible during simulation. Be aware that Scopes store data and can be memory intensive.
Connecting the signal to a root-level Outport block.
This method reduces diagram clutter by eliminating the need to use Scope blocks to log signals. Data is available only when simulation is paused or completed.
Setting the signal's signal logging properties.
This method eliminates the need to add blocks. Data is available only when simulation is paused or completed.
All of these methods allow you to specify the names of the workspace variables used to save signal data and to limit the amount of data logged for a particular signal.
See Simulink Reference for the To Workspace and Outport blocks for information on using these blocks to log signal data. See the documentation of the sim command for some data logging capabilities that are available only for programmatic simulation.
You can globally enable or disable signal logging for a model by checking or unchecking the Signal logging option on the Data Import/Export pane of the Configuration Parameters dialog box (see Signal logging ). Simulink logs signals only if this option is checked. If the option is not checked, Simulink ignores the signal logging settings for individual signals.
To enable signal logging for a signal, select the Log signal data option on the signal's Signal Properties dialog box. See Signal Properties Dialog Box for more information.
You can enable signal logging programmatically for selected blocks with the outport DataLogging property. You can set this property using the set_param command. For example:
At the MATLAB Command Window, open a model. Type
vdp
Select a block in that model. For example, select the Mux block.
Get the port handles of the selected block.
get_param(gcb,'PortHandles')
Enable signal logging for the desired outport port.
set_param(ans.Outport(1),'DataLogging','on')
The logged signal indicator (
) appears.
By default, Simulink displays an indicator on each signal whose Signal Properties > Log signal data option is enabled. For example, in the following model the output of the Sine Wave block is logged:

A logged signal can also be a test point. See Working with Test Points for information about test points.
To turn display of logging indicators on or off, select or clear Port/Signal Displays > Testpoint/Logging Indicators from the Simulink Format menu.
You can assign a name, called the logging name, to the object used to log data for a signal during simulation. To specify a log name for a signal, select Custom from the Logging name list on the signal's Signal Properties dialog box and enter the custom name in the adjacent text field.
If you do not specify a custom logging name, Simulink uses the signal name, or if there is no name, Simulink generates a default name that is composed of the block name and port number. For example, if the block name is MyBlock and the signal being logged is the first output of this block, Simulink generates the following name: SL_MyBlock1.
The Data panel of the Signal Properties dialog box lets you limit the amount of data logged for a signal. For example, you can specify the maximum amount of data to be logged for a signal or a decimation factor that causes Simulink to skip a specified number of time steps before logging a signal value. See Data for more information.
A virtual signal is a signal that graphically represents other signals or parts of other signals. Virtual signals are purely graphical entities; they have no functional or mathematical significance. The source of a virtual signal is always a virtual block, like a Mux block or Selector block. See Virtual Signals and Mux Signals for more information.
The nonvirtual components of a virtual signal are called regions. A virtual signal can contain the same region more than once. For example, if the same nonvirtual signal is connected to two input ports of a Mux block, the block outputs a virtual signal that has two regions.
The log of a virtual signal that contains duplicate regions includes all of the regions, even though the data in each is the same. Logged virtual signal regions appear in the log in a Simulink.TsArray object. The log gives the duplicate regions unique names, using the syntax: <signal_name>_reg<#counter>.
You can log multidimensional signals, which are signals whose elements are nonscalar. The techniques for logging multidimensional signals are the same as those for logging any other signal. See Signal Dimensions for information about multidimensional signals.
You can log Simulink composite signals, which are called buses. The hierarchy of a bus signal is preserved in the logsout object. The logged name of a signal in a virtual bus derives from the name of the source signal. The logged name of a signal in a nonvirtual bus derives from the applicable bus object, and can differ from that of the source signal. See Using Composite Signals and Using Bus Objects for information about those capabilities.
You can log any signal that is defined as a test point in a referenced model. For information about test points, see Designating a Signal as a Test Point. For information about referenced models, see Referencing a Model.
To log test pointed signals in referenced models, select the Model block and then select Log referenced signals from the model editor's Edit menu or from the block's context menu.
The Model Reference Signal Logging dialog box appears.

The dialog box contains the following panes and controls.
This pane displays the contents of the referenced model as a tree control with expandable nodes. The top-level node represents the referenced model. Expanding this node displays the subsystems that the referenced model contains and any models that it itself references. Expanding a subsystem node displays the subsystems that it contains and the models that it references.
Refreshes the dialog box to reflect changes in the model hierarchy.
This pane displays the test points of the model or subsystem selected in the Model Hierarchy pane. See Working with Test Points. Check the check box next to a test point's name to specify that it should be logged.
Checking this check box causes Simulink to log the signals that the referenced model specifies should be logged.
This pane is enabled if Log signals as specified by the referenced model is not selected. In this case, the controls on this pane allow you to specify the signal logging properties of the signal selected in the Signals pane. The values that you specify override for this instance of the referenced model those specified by the model itself. The controls correspond to the controls of the same name on the Signal Properties dialog box. See Signal Properties Dialog Box for information on how to use them.
To view logged signal data, either check Configuration Parameters > Data Import/Export > Inspect signals when simulation is stopped/paused or select Tools > Inspect Logged Signals from the model editor's menu bar. The first method causes Simulink to display logged signals in the MATLAB Time Series Tools viewer (see Time Series Tools) whenever a simulation ends or you pause a simulation. The second method causes Simulink to display the data immediately.
Note You must run the simulation first before selecting Tools > Inspect Logged Signals. Otherwise, selecting this command has no effect. |
Simulink saves signal data that it logs during simulation in a Simulink data object of type Simulink.ModelDataLogs that resides in the MATLAB workspace. The name of the object's handle is logsout by default. The Data Import/Export configuration pane (see Data Import/Export Pane) allows you to specify another name for this object. See Simulink.ModelDataLogs for information on extracting signal data from this object. The signal logs for particular model elements are contained in the objects in the following table.
| Model Element | Signal Data Object |
|---|---|
| Top-level or referenced model | Simulink.ModelDataLogs |
| Subsystem in a model | Simulink.SubsysDataLogs |
| Scope block in a model | Simulink.ScopeDataLogs |
| Signal other than a mux or bus | Simulink.Timeseries |
| Mux or bus signal | Simulink.TsArray |
Names that include space or newline characters can improve the readability of a block diagram, but referencing names that include such characters in a data log requires special techniques. These techniques allow the MATLAB parser to process the names even though spaces and newlines are not legal in MATLAB identifiers. Signal names in data logs can have spaces or newlines in their names under the following circumstances:
The signal is named, and the name includes blank or newline characters.
The signal is unnamed, and originates in a block whose name includes blank or newline characters.
The signal exists in a subsystem or referenced model, and the name of the subsystem or Model block, or of any superior block, includes blank or newline characters.
The following three examples show a signal whose name contains a space, a signal whose name contains a newline, and an unnamed signal that originates in a block whose name contains a newline:

If you execute these examples with data logging enabled in the Data Import/Export pane, accepting the default logging object name logsout, and then type logsout in the MATLAB Command Window, MATLAB displays the following data log:
logsout =
Simulink.ModelDataLogs (model_name):
Name Elements Simulink Class
('x y') 1 Timeseries
('a
b') 1 Timeseries
('SL_Sine
Wave1') 1 Timeseries
You cannot access any of the Timeseries objects in this log using TAB name completion, or by typing the name to MATLAB, because the space or newline in each name appears to the MATLAB parser as a separator between identifiers. For example:
>> logsout.x y
??? logsout.x y
|
Error: Unexpected MATLAB expression.To reference a Timeseries object whose name contains a space, as in the first example above, single-quote the element containing the space:
>> logsout.('x y')
Name: 'x y'
BlockPath: 'model_name/Sine'
PortIndex: 1
SignalName: 'x y'
ParentName: 'x y'
TimeInfo: [1x1 Simulink.TimeInfo]
Time: [51x1 double]
Data: [51x1 double]To reference a Timeseries object whose name contains a newline, as in the second example above, concatenate to construct the element containing the newline:
>> cr=sprintf('\n')
>> logsout.(['a' cr 'b'])
The same techniques work when a space or newline in a data log derives from the name of:
An unnamed logged signal's originating block
A subsystem or Model block that contains any logged signal
Any block that is superior to such a block in the model hierarchy
This code can reference logged data for the signal in the third example above:
>> logsout.(['SL_Sine' cr 'Wave1'])
For names with multiple spaces, newlines, or both, repeat and combine the two techniques as needed to specify the intended name to MATLAB. No analogous techniques exist for TAB name completion, which never works with names that contain space or newline characters.
Before a simulation ends, you can extract and write the currently logged signal data from Simulink.ModelDataLogs with the set_param WriteDataLogs command. The currently logged signal is the partial data logged between when the simulation started and when you request an extraction of the signal data. If you use this command during the simulation, Simulink writes the current logging variable values to the MATLAB workspace. If you use this command at the end of the simulation, Simulink writes the values from the last simulation to the MATLAB workspace.
To use this command, type the following at the MATLAB Command Window.
set_param(bdroot,'SimulationCommand','WriteDataLogs')
Enabling signal logging on a signal-by-signal basis allows you to store signal data without modifying the structure of the Simulink diagram. For example, use the following steps to log and access the signal data for the vertical velocity signal w in the F14 model.
Open the F14 model by typing f14 at the MATLAB command prompt.
Right-click on the signal labeled w and select the Signal Properties menu.

In the Signal Properties dialog box that opens, select the Log signal data option. The logging name initializes to the signal's name.

Click the OK button on the Signal
Properties dialog box. The 'blue antenna' icon
appears on the signal
labeled w, indicating that this signal will be
logged during simulation.
Ensure that Configuration Parameters > Data Import/Export Signal logging is selected and that the logging name is set to the default variable logsout.
Run the F14 simulation. The logged signal data is stored in a Simulink.ModelDataLogs object named logsout in the MATLAB workspace. Typing logsout at the MATLAB command prompt displays the following
logsout = Simulink.ModelDataLogs (f14): Name Elements Simulink Class w 1 Timeseries
Type logsout.w to view the information stored for the signal w.
logsout.w
Name: 'w'
BlockPath: 'f14/Aircraft Dynamics Model'
PortIndex: 1
SignalName: 'w'
ParentName: 'w'
TimeInfo: [1x1 Simulink.TimeInfo]
Time: [1353x1 double]
Data: [1353x1 double]To inspect the signal using the MATLAB Time Series Tools, select Inspect Logged Signals from the f14 model editor's Tools menu (see Time Series Tools in the MATLAB documentation).
When you log data using the Structure, Structure with time, or Timeseries format, each field that contains logged data can contain at most 2^31-1 bytes on a 32–bit platform, and 2^48-1 bytes on a 64–bit platform.
When you log data using Array format, each array that contains logged data can contain at most 2^31-1 bytes on a 32–bit platform, and 2^48-1 bytes on a 64–bit platform.
Simulink data logging does not support the following types of signals:
Output of a Function-Call Generator block
Signal connected to the input of a Merge block
Rapid Accelerator mode does not support signal logging. For more information, see Using Scopes and Viewers with Rapid Accelerator Mode.
![]() | Introduction | Importing Data from a Workspace | ![]() |

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |