| Simulink® | ![]() |
| On this page… |
|---|
Limiting the Data Logged for a Signal Logging Referenced Model Signals Example: Logging Signal Data in the F14 Model |
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 only available when simulation is paused or completed.
Setting the signal's signal logging properties.
This method eliminates the need to add blocks. Data is only available 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.
Simulink does not support signal logging for the following types of signals:
Output of a Function-Call Generator block
Signal connected to the input of a Merge block
Multidimensional signals are supported.
Bus hierarchy is supported. The hierarchy of a bus signal is preserved in the logsout object. See Using Composite Signals for details about muxes and buses.
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).
Note If you enable signal logging for a signal, Simulink designates the signal as a test point automatically. This is because a signal must be accessible to be logged (see Designating a Signal as a Test Point for more information). |
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.
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.
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.
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 the Inspect signals when simulation is stopped/paused in the Data Import/Export pane of the Configuration Parameters dialog box 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 in the online MATLAB documentation) 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 in the online Simulink reference 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. The Simulink.ModelDataLogs object is the container for these objects.
| Modeling Element | Signal Data Object |
|---|---|
| Signal in this model | Simulink.Timeseries |
| Model referenced by this model | Simulink.ModelDataLogs |
| Subsystem | Simulink.SubsysDataLogs |
| Bus, mux, vector concatenate | Simulink.TsArray |
| Scope | Simulink.ScopeDataLogs |
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, check the Log signal data option. Notice that the Test point option automatically becomes checked and 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 the Signal logging option on the Data Import/Export pane of the Configuration Parameters dialog box is checked 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 in the online MATLAB documentation).
Named signals that are used for signal logging but do not have an associated Simulink.Signal object can have names that include space and newline characters, as described in Naming Signals. Such names can improve the readability of a block diagram, but referencing them requires require special techniques when they appear in a data log. These techniques allow the MATLAB parser to process the names even though spaces and newlines are not legal in MATLAB identifiers.
Space and newline characters can also appear in a data log when an unnamed logged signal originates in a block whose name contains any spaces or newlines. The Simulink software constructs a name for the signal based on the block name, and the constructed name inherits the characters that the block name contains; these characters then appear in the data log. This situation often arises, because many blocks have spaces in their default names. One way to avoid it is to name the logged signal, thus avoiding the default name.
The following model includes 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 this model 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, 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, concatenate to construct the element containing the newline:
>> cr=sprintf('\n')
>> logsout.(['a' cr 'b'])
The same technique works when the newline derives from a block name used to generate a name for an unnamed signal:
>> 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')
![]() | The Signal Selector | Initializing Signals and Discrete States | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |