Documentation

Configure a Signal for Logging

Mark a Signal for Signal Logging

Enable logging by marking a signal, using one of the following techniques:

The Simulink® Editor menu options generally are the simplest way to mark signals for signal logging.

A signal for which you enable signal logging is a logged signal. By default, Simulink displays a logged signal indicator for each logged signal.

Enable Signal Logging Using Simulink Editor Menu Options

  1. In the Simulink Editor, select one or more signals.

  2. Click the Simulation Data Inspector button arrow and click Log Selected Signals to Workspace.

Alternatively, you can select one or more signals and check Simulation > Output > Log Selected Signals to Workspace.

If you select multiple signals, the signal logging configuration that Simulink sets depends on whether any of the selected signals are marked for signal logging.

Signal Logging for Selected SignalsResult of Enabling the Log/Unlog Selected Signals Option

At least one of the selected signals does not have signal logging enabled.

Enables signal logging for all the selected signals

All selected signals have signal logging enabled.

Disables signal logging for all the selected signals

Enable Signal Logging Using Signal Properties

  1. In the Simulink Editor, right-click the signal.

  2. From the context menu, select Signal Properties.

  3. In the Signal Properties dialog box, in the Logging and accessibility tab, select Log signal data.

  4. Click OK.

Enable Signal Logging Using Model Explorer

  1. In the Model Explorer Model Hierarchy pane, select the node that contains the signal for which you want to enable signal logging.

  2. If the Contents pane does not display the DataLogging property, set the Column view to Signals or add the DataLogging property to the current view. For details about column views, see Control Model Explorer Contents Using Views.

  3. Enable the DataLogging property for one or more signals.

However, the Model Explorer does not display unnamed signals. To display the DataLogging property (which sets up logging for a signal) can require that you reconfigure the Model Explorer.

Programmatic Interface

To enable signal logging programmatically for selected blocks, use the outport DataLogging property. Set this property using the set_param command. For example:

  1. At the MATLAB® Command Window, open a model. Type

    vdp
  2. Get the port handles of the signal that you want to log. For example, for the Mu block outport signal.

    ph = get_param('vdp/Mu','PortHandles')
  3. Enable signal logging for the desired outport signal.

    set_param(ph.Outport(1),'DataLogging','on')

    The logged signal indicator appears.

Logging Referenced Model Signals

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.

Specify Signal-Level Logging Name

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.

Signal-Level Logging Name in the Editor

  1. In the Simulink Editor, right-click the signal.

  2. From the context menu, select Signal Properties.

  3. Specify the logging name:

    1. In the Signal Properties dialog box, select the Logging and accessibility tab.

    2. From the Logging name list, select Custom.

    3. Enter the logging name in the adjacent text field.

Signal-Level Logging Name in Model Explorer

  1. In the Model Explorer Model Hierarchy pane, select the node that contains the signal for which you want to specify a logging name.

  2. If the Contents pane does not display the LoggingName property, add the LoggingName property to the current view. For details about column views, see Control Model Explorer Contents Using Views.

  3. Enter a logging name for one or more signals using the LoggingName column.

Signal-Specific Logging Name Specified Programmatically

Enable signal logging programmatically for selected blocks with the outport DataLogging property. Set this property using the set_param command.

  1. At the MATLAB Command Window, open a model. For example, type:

    vdp
  2. Get the port handles of the signal that you want to log. For example, for the Mu block outport signal:

    ph = get_param('vdp/Mu','PortHandles');
  3. Enable signal logging for the desired outport signal:

    set_param(ph.Outport(1),'DataLogging','on');

    The logged signal indicator appears.

  4. 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');

Limit Data Logged

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.

Use Signal Properties to Limit Logged Data

  1. In the Simulink Editor, right-click the signal.

  2. From the context menu, select Signal Properties.

  3. 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

Use Model Explorer to Limit Data Logged

  1. 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.

  2. 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 Control Model Explorer Contents Using Views.

  3. To specify a decimation factor, edit the Decimation and DecimateData properties. To limit the number of samples logged, edit the LimitDataPoints property.

Set Sample Time for a Logged Signal

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

Usage Notes

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).

Related Examples

Was this topic helpful?