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 of the selected signals

All selected signals have signal logging enabled.

Disables signal logging for all of the selected signals

Enable Signal Logging Using the Signal Properties Dialog Box

  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

    Note:   The only signals that Model Explorer displays are named signals. See Signal Names.

  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

  • Might need to be reconfigured to display the DataLogging property (which sets up logging for a signal)

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 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 takes depends on the signal logging format:

  • Dataset — Uses a blank name

  • ModelDataLogs — 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 name SL_MyBlock1.

    Note:   The signal-level logging name is distinct from the model-level signal logging name, which 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 the Signal Logging Data for a Model.

Using the Simulink Editor to Specify a Signal-Level Logging Name

  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.

Using the Model Explorer to Specify a Signal-Level Logging Name

  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.

Programmatically Specifying a Signal-Specific Logging Name

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 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 the Data Logged for a Signal

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.

Using the Signal Properties Dialog Box to Limit the Amount of Data Logged

  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

Using the 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.

Was this topic helpful?