Enable logging by marking a signal, using one of the following techniques:
The Simulink® Editor menu options are generally the simplest way to mark signals for logging.
A signal for which you enable logging is a logged signal. By
default, Simulink displays a logged signal indicator for each logged signal.
In the Simulink Editor, select one or more signals.
On the Simulation tab, click Log Signals.
In the Simulink Editor, right-click the signal.
From the context menu, select Properties.
In the Signal Properties dialog box, in the Logging and accessibility tab, select Log signal data.
Click OK.
Alternatively, you can select the Log Selected Signals from the context menu that appears when you right-click the selected signal.
The Model Data Editor displays a flat list of signals in your model. You can sort, group, and filter the list. Use this technique to enable logging for:
Many signals at once.
Signals that are not close to each other in the block diagram.
Signals that are difficult to locate in a large model or subsystem hierarchy.
To select signals to log using the Model Data Editor:
Open the Model Data Editor. On the Modeling tab, click the Model Data Editor button.
Select the Signals tab in the Model Data Editor.
Select Instrumentation
in the drop-down.
Check the boxes in the Log Data column for signals you would like to log.
For more information about the Model Data Editor, see Configure Data Properties by Using the Model Data Editor.
To enable signal logging programmatically for selected blocks, use the output
DataLogging
property. Set this property using the
set_param
command. For example:
At the MATLAB® Command Window, open a model. Type
vdp
Get the port handles of the signal that you want to log. For example, for the Mu block output port signal.
ph = get_param('vdp/Mu','PortHandles')
Enable signal logging for the desired output port signal.
set_param(ph.Outport(1),'DataLogging','on')
The logged signal indicator appears.
You can log any logged signal in a referenced model. Use the Signal Logging Selector to configure signal logging for a model reference hierarchy. For details, see Models with Model Referencing: Overriding Signal Logging Settings.
You can specify a signal-level logging name to the object that Simulink uses to store logging data for a signal. Specifying a signal-level logging name can be useful for signals that are unnamed or that share a duplicate name with another signal in the model hierarchy. Specifying signal-level logging names, rather than using the names that Simulink generates, can make the logged data easier to analyze.
To specify a signal-level logging name, use one of the following approaches:
If you do not specify a custom signal-level logging name, Simulink uses the signal name. If the signal does not have a name, the action Simulink uses a blank name.
Note
The signal-level logging name is distinct from the model-level signal logging name.
The model-level signal logging name is the name for the object containing all the logged
signal data for the whole model. The default model-level signal logging name is
logsout
. For details about the model-level signal logging name, see
Specify a Name for Signal Logging Data.
In the Simulink Editor, right-click the signal.
From the context menu, select Signal Properties.
Specify the logging name:
In the Signal Properties dialog box, select the Logging and accessibility tab.
From the Logging name list, select
Custom
.
Enter the logging name in the adjacent text field.
In the Model Explorer Model Hierarchy pane, select the node that contains the signal for which you want to specify a logging name.
If the Contents pane does not display the
LoggingName
property, add the LoggingName
property to the current view. For details about column views, see Model
Explorer.
Enter a logging name for one or more signals using the
LoggingName
column.
Enable signal logging programmatically for selected blocks with the output port
DataLogging
property. Set this property using the
set_param
command.
At the MATLAB Command Window, open a model. For example, type:
vdp
Get the port handles of the signal that you want to log. For example, for the Mu block output port signal:
ph = get_param('vdp/Mu','PortHandles');
Enable signal logging for the desired output port signal:
set_param(ph.Outport(1),'DataLogging','on');
The logged signal indicator appears.
Issue commands that use the DataLoggingNameMode
and
DataLoggingName
parameters. For example:
set_param(ph.Outport(1),'DataLoggingNameMode','Custom'); set_param(ph.Outport(1),'DataLoggingName','x2_log');
You can limit the amount of data logged for a signal by:
Specifying a decimation factor
Limiting the number of samples saved to be only the most recent samples
You can limit data logged for a signal by using the Signal Properties dialog box, the Model Explorer, the Signal Logging Selector, or programmatically. The following sections describe the first two approaches.
In the Simulink Editor, right-click the signal.
From the context menu, select Signal Properties.
In the Signal Properties dialog box, click the Logging and accessibility tab. Then select one or both of these options:
Limit data points to last
Decimation
In the Model Explorer Model Hierarchy pane, select the node that contains the signal for which you want to limit the amount of data logged.
If the Contents pane does not display the
DataLoggingDecimation
property or the
DataLoggingLimitDataPoints
property, add one or both of those
properties to the current view. For details about column views, see Model
Explorer.
To specify a decimation factor, edit the Decimation
and
DecimateData
properties. To limit the number of samples logged,
edit the LimitDataPoints
property.
To set the sample time for a logged signal, in the Signal Properties dialog box, use the Sample Time option. This option:
Separates design and testing, because you do not need to insert a Rate Transition block to have a consistent sample time for logged signals
Reduces the amount of logged data for a continuous time signal, for which setting decimation is not relevant
Eliminates the need to postprocess logged signal data for signals with different sample times
Do not specify a sample time for:
Frame-based signals
Conditional subsystems (for example, function-call or triggered subsystems) and conditional referenced models, which require an inherited sample time
If you simulate in SIL mode, signal logging ignores the sample times you specify for logged signals.
When you mark a signal for signal logging, Simulink inserts a hidden To Workspace block. When you specify a sample time for a logged signal, Simulink inserts a hidden Rate Transition block and a hidden To Workspace block.
Specifying a sample time for signal logging does not affect the simulation result.
However, it is possible that the signal logging output for a logged signal varies
depending on whether you specify a sample rate. For example, the interpolation method can
differ depending on whether you specify a sample time for signal logging. Suppose that a
model includes a continuous signal and the sample time is inherited
(-1
). The logged output for that signal shows that the interpolation
method is linear
.
logsout.get(1).Values.DataInfo
tsdata.datametadata Package: tsdata Common Properties: Units: '' Interpolation: linear (tsdata.interpolation)
If you change the sample time to be continuous (0
), the logged
output for that signal shows that the interpolation method is zoh
(zero-order hold).