Main Content

Override Signal Logging Settings

You can use signal logging to capture signal data from a simulation without adding blocks to your model. For more information, see Save Signal Data Using Signal Logging.

As you develop a model, you may want to override the signal logging settings for a specific simulation run. You can use the Signal Logging Selector or a programmatic interface to override signal logging properties without changing the model in the Simulink® Editor. By overriding signal logging settings, you can avoid recompiling a model and reduce memory overhead.

To override signal logging settings, you can use one or a combination of these two methods:

Benefits of Overriding Signal Logging Settings

Overriding signal logging properties is useful when you want to:

  • Focus on only a few signals by disabling logging for most of the signals marked for logging. You can mark a superset of signals for logging and then select different subsets of those signals for logging.

  • Exclude a few signals from the signal logging output.

  • Override specific signal logging properties, such as decimation, for a signal.

  • Collect only what you need when running multiple test vectors.

Scope of Signal Logging Setting Overrides

When you override signal logging settings, the software saves the specified configuration in the model and uses those override settings when you simulate the model. However, the software does not change the signal logging settings in the Signal Properties dialog box for each signal in the model.

If you close and reopen the model, the signal logging overrides that you made are in effect if the logging mode is set to override signals for that model. When the model displays the signal logging indicators, it displays the indicators for all logged signals, including logged signals that you have overridden.

Note

When you have a model with signals marked for signal logging that has been simulated in rapid accelerator mode, the software rebuilds the model if you override the signal logging settings and simulate the model in rapid accelerator mode again.

Override Signal Logging Settings with Signal Logging Selector

You can use the Signal Logging Selector to interactively view and override signal logging settings.

To apply override settings using the Signal Logging Selector, Logging Mode must be set to Override signals. If you set the Logging Mode to Log all signals as specified in model after overriding signal logging settings, the logging settings defined in the model appear in the Signal Logging Selector. The override settings are greyed out, indicating that you cannot override these settings. To reactivate the override settings, set Logging Mode to Override signals. Using the Signal Logging Selector to override logging for a specific signal does not affect the signal logging indicator for that signal.

  1. Open the Signal Logging Selector. On the Modeling tab, click Model Settings to open the Configuration Parameters dialog box. Then, in the Data Import/Export pane, click Configure Signals to Log.

    The Configure Signals to Log button in the Configuration Parameters dialog box.

    Tip

    To enable the Configure Signals to Log button, select the Signal logging configuration parameter.

  2. Set Logging Mode to Override signals.

    In the Signal Logging Selector, if you override some signal logging settings and then set Logging Mode to Log all signals as specified in model, the logging settings defined in the model appear in the Signal Logging Selector. The override settings are greyed out, indicating that you cannot override these settings. To reactivate the override settings, set Logging Mode to Override signals. Using the Signal Logging Selector to override logging for a specific signal does not affect the signal logging indicator for that signal.

    The Signal Logging Selector with the Logging Mode list expanded to show the Override signals option.

    Note

    The Override signals setting affects all levels of the model hierarchy. This setting can result in turning off logging for any signal throughout the hierarchy. To review settings, select the appropriate node in the Model Hierarchy pane.

  3. View the node containing the logged signals that you want to override. If necessary, expand nodes or configure the Model Hierarchy pane to display masked subsystems. See View Logging Configuration Using the Signal Logging Selector.

  4. Override signal logging settings.

    When a model includes referenced models, the check box in the Model Hierarchy pane indicates the override configuration for the model corresponding to the node.

    Check BoxSignal Logging Configuration
    Filled box with white check mark

    For the top-level model node, logs all logged signals in the top model.

    For a Model block node, logs all logged signals in the model reference hierarchy for that block.

    Empty box

    For the top-level model node, disables logging for all logged signals in the top-level model.

    For a Model block node, disables logging for all signals in the model reference hierarchy for that block.

    Filled box with white dash

    For the top-level model node, logs all logged signals that have the DataLogging setting enabled.

    For a Model block node, logs all logged signals in the model reference hierarchy for that block that have the DataLogging setting enabled.

For an example of how to use the Signal Logging Selector to override the signal logging settings, see Override Signal Logging Settings.

Override Signal Logging Settings Programmatically

You can override signal logging settings programmatically using the MATLAB® command line.

To configure signal logging override settings programmatically, use functions and properties of the following objects:

  • Simulink.SimulationData.ModelLoggingInfo — Override settings for a model. This object corresponds to the overall Signal Logging Selector interface.

  • Simulink.SimulationData.SignalLoggingInfo — Override settings for a specific signal. This object corresponds to a row in the logging property table in the Signal Logging Selector.

  • Simulink.SimulationData.LoggingInfo — Override settings for the LoggingInfo property of a Simulink.SimulationData.SignalLoggingInfo object. This object corresponds to the editable columns in a row in the logging property table in the Signal Logging Selector.

To query a model for its signal logging override status, use the DataLoggingOverride model parameter.

get_param(mdl,"DataLoggingOverride")

To apply a signal logging override configuration, use the set_param function with the DataLoggingOverride model parameter.

set_param(mdl,"DataLoggingOverride",mdlInfoObject)

You can control the kinds of systems from which to include logged signals. By default, the Simulink.SimulationData.ModelLoggingInfo object includes logged signals from:

  • Libraries

  • Masked subsystems

  • Referenced models

  • Active variants

These sections describe how to perform some common signal logging configuration tasks programmatically.

For additional examples, see:

Create Model Logging Override Object with Logged Signals

You can create a model logging override object for the model sldemo_mdlref_bus and automatically add each logged signal in the model to that object. The model sldemo_mdlref_bus has four signals marked for logging.

mdl = 'sldemo_mdlref_bus';
open_system(mdl)
mdlInfo = Simulink.SimulationData.ModelLoggingInfo.createFromModel(mdl)
mdlInfo = 
  ModelLoggingInfo with properties:

                     Model: 'sldemo_mdlref_bus'
               LoggingMode: 'OverrideSignals'
    LogAsSpecifiedByModels: {}
                   Signals: [1x4 Simulink.SimulationData.SignalLoggingInfo]

The LoggingMode property is set to 'OverrideSignals', which configures the model logging override object to log only the signals specified in the Signals property.

Apply the model override object settings. The software saves the settings when you save the model.

set_param(mdl,'DataLoggingOverride',mdlInfo);

Set Logging Mode of Model Logging Override Object

You can use the setLogAsSpecifiedInModel function to override signal logging settings specified in a model. For example, you can log only the top model or only a referenced model in a model hierarchy. The model sldemo_mdlref_bus contains a Model block named CounterA that references the model sldemo_mdlref_counter_bus. In total, four signals are marked for logging. The top model has three signals marked for logging: COUNTERBUS, INCREMENTBUS, and OUTERDATA. The referenced model has one signal marked for logging: INNERDATA.

mdl = 'sldemo_mdlref_bus';
mdlInner = 'sldemo_mdlref_bus/CounterA';
open_system(mdl)

Create an empty Simulink.SimulationData.ModelLoggingInfo object so that no signals are logged when the logging mode is set to the override settings specified in the Signals property.

mdlInfo = Simulink.SimulationData.ModelLoggingInfo(mdl);

You can use the setLogAsSpecifiedInModel function to log only signals in the top model using the logging settings specified in that model. Set the outer model to log signals as specified in the model. Then, set the inner model to use override settings. Since the Signals property vector is empty, no signals are logged when override settings are applied.

mdlInfo = setLogAsSpecifiedInModel(mdlInfo,mdl,true);
mdlInfo = setLogAsSpecifiedInModel(mdlInfo,mdlInner,false);

The getLogAsSpecifiedInModel function returns the logging mode.

outerLogMode = getLogAsSpecifiedInModel(mdlInfo,mdl)
outerLogMode = logical
   1

innerLogMode = getLogAsSpecifiedInModel(mdlInfo,mdlInner)
innerLogMode = logical
   0

Apply the model override object settings. Then, simulate the model. The software logs only those signals marked for logging in the top model.

set_param(mdl,'DataLoggingOverride',mdlInfo);
sim(mdl);
topOut
topOut = 
Simulink.SimulationData.Dataset 'topOut' with 3 elements

                         Name          BlockPath                             
                         ____________  _____________________________________ 
    1  [1x1 Signal]      COUNTERBUS    sldemo_mdlref_bus/Concatenate        
    2  [1x1 Signal]      OUTERDATA     sldemo_mdlref_bus/CounterA           
    3  [1x1 Signal]      INCREMENTBUS  sldemo_mdlref_bus/IncrementBusCreator

  - Use braces { } to access, modify, or add elements using index.

You can also use the setLogAsSpecifiedInModel function to log only signals in the referenced model using the logging settings specified in that model. Set the outer model to use override settings. Then, set the inner model to log signals as specified in the model.

mdlInfo = setLogAsSpecifiedInModel(mdlInfo,mdl,false);
mdlInfo = setLogAsSpecifiedInModel(mdlInfo,mdlInner,true);

To verify that the logging mode for the top model and inner model have changed, you can use the getLogAsSpecifiedInModel function.

outerLogMode = getLogAsSpecifiedInModel(mdlInfo,mdl)
outerLogMode = logical
   0

innerLogMode = getLogAsSpecifiedInModel(mdlInfo,mdlInner)
innerLogMode = logical
   1

Apply the model override object settings. Then, simulate the model. This time, the software logs only the INNERDATA signal.

set_param(mdl,'DataLoggingOverride',mdlInfo);
sim(mdl);
topOut
topOut = 
Simulink.SimulationData.Dataset 'topOut' with 1 element

                         Name       BlockPath                                
                         _________  ________________________________________ 
    1  [1x1 Signal]      INNERDATA  ...erA|sldemo_mdlref_counter_bus/COUNTER

  - Use braces { } to access, modify, or add elements using index.

See Also

Objects

Tools

Related Topics