Main Content

Simulink.SimulationData.ModelLoggingInfo

Signal logging override settings for model

Description

Use a Simulink.SimulationData.ModelLoggingInfo object to override signal logging settings for a model without changing the model in the Simulink® Editor.

Simulink.SimulationData.ModelLoggingInfo objects are a collection of Simulink.SimulationData.SignalLoggingInfo objects that specify all signal logging override settings for a model.

Use object functions and properties of this object to:

  • Turn off logging for a signal or a Model block.

  • Change logging settings for any signals that are marked for logging within a model.

You can control whether a top model and referenced models override signal logging settings or use the signal logging settings specified by the model. Use the LoggingMode and LogAsSpecifiedByModels properties to control which logging settings to apply.

Logging Mode for ModelsProperty Settings

For top model and all referenced models, use logging settings specified in the model.

Set LoggingMode to LogAllAsSpecifiedInModel.

For top model and all referenced models, use override signal logging settings.

Set LoggingMode to OverrideSignals.

For top model and referenced models, use a mix of override signal logging settings and the signal logging settings specified in the model.

Set LoggingMode to OverrideSignals.

Include models you want to ignore override signal logging settings in the LogAsSpecifiedByModels cell array.

If you use the Simulink.SimulationData.ModelLoggingInfo constructor, specify a Simulink.SimulationData.SignalLoggingInfo object for each logged signal for which you want to override logging settings.

To check that you have specified valid signal logging override settings for a model, use the verifySignalAndModelPaths function with the Simulink.SimulationData.ModelLoggingInfo object for the model.

Creation

Description

mdlInfo = Simulink.SimulationData.ModelLoggingInfo(mdl)creates a Simulink.SimulationData.ModelLoggingInfo object for the specified top model.

example

Input Arguments

expand all

Name of top model for which to create a Simulink.SimulationData.ModelLoggingInfo object, specified as a string or character vector.

Properties

expand all

Signal logging override status, specified as 'OverrideSignals' or 'LogAllAsSpecifiedInModel'.

  • 'OverrideSignals' — Uses the logging settings for signals as specified in the Signals property. For models where getLogAsSpecifiedInModel is:

    • true — Simulink logs all signals as specified in the model.

    • false — Simulink logs only the signals specified in the Signals property of the Simulink.SimulationData.ModelLoggingInfo object.

  • 'LogAllAsSpecifiedInModel' — Logs signals in the top model and all referenced models as specified in the model. Simulink honors the signal logging indicators (blue antennae) and ignores the Signals property.

To change the logging mode for an individual model, such as the top model or a given referenced model, use the setLogAsSpecifiedInModel function. To quickly change the logging mode for the top model and all referenced models, set the LoggingMode property to 'LogAllAsSpecifiedInModel'. For example, to set the model sldemo_mdlref_bus.slx and all referenced models to log signals as specified in the model, you can set the LoggingMode property of the Simulink.SimulationData.ModelLoggingInfo object to 'LogAllAsSpecifiedInModel'.

mdlInfo = Simulink.SimulationData.ModelLoggingInfo("sldemo_mdlref_bus");
mdlInfo.LoggingMode = 'LogAllAsSpecifiedInModel'

Source of signal logging settings for the top model or a top-level Model block, specified as a cell array.

When LoggingMode is set to 'OverrideSignals', the LogAsSpecifiedByModels cell array specifies the top models and top-level Model blocks that ignore the 'OverrideSignals' setting and log signals as specified in the models or Model blocks.

  • For the top model and top-level Model blocks that the cell array includes, the software ignores the Signals property overrides.

  • For a model or Model block that the cell array does not include, the software uses the Signals property to determine which signals to log.

When LoggingMode is set to 'LogAllAsSpecifiedInModel', the software ignores the LogAsSpecifiedByModels property.

Use the getLogAsSpecifiedInModel function to determine whether the top model or top-level Model block logs signals as specified in the model (default logging). Use setLogAsSpecifiedInModel to turn default logging on and off for a top model or top-level Model block.

Signals that have signal override settings, specified as a vector of Simulink.SimulationData.SignalLoggingInfo objects.

Object Functions

Simulink.SimulationData.ModelLoggingInfo.createFromModelCreate Simulink.SimulationData.ModelLoggingInfo object for top model with override settings for each logged signal in model
findSignalFind index of signals in Signals property vector
getLogAsSpecifiedInModelDetermine whether model logs as specified in model or uses override settings
setLogAsSpecifiedInModelSet logging mode for top model or top-level Model block
verifySignalAndModelPathsVerify paths in Simulink.SimulationData.ModelLoggingInfo object

Examples

collapse all

You can control whether a top-level model and referenced models use override signal logging settings or use the signal logging settings specified by the model. This example shows how to log all signals as specified in the top model and all referenced models.

The model sldemo_mdlref_bus has four signals marked for logging. For more information about the model, see Interface Specification Using Bus Objects.

mdl = "sldemo_mdlref_bus";
open_system(mdl)

Create a model logging override object.

mdlInfo = Simulink.SimulationData.ModelLoggingInfo(mdl);

To specify whether to use the signal logging settings as specified in the model and all referenced models, or to override those settings, use the LoggingMode property of the model logging override object.

mdlInfo.LoggingMode = 'LogAllAsSpecifiedInModel'
mdlInfo = 
  ModelLoggingInfo with properties:

                     Model: 'sldemo_mdlref_bus'
               LoggingMode: 'LogAllAsSpecifiedInModel'
    LogAsSpecifiedByModels: {}
                   Signals: [0x0 Simulink.SimulationData.SignalLoggingInfo]

Use the set_param function to apply the model override object settings. The software saves the settings when you save the model.

set_param(mdl,'DataLoggingOverride',mdlInfo);

Simulate the model. The signal logging output is stored in topOut.

sim(mdl);
topOut
topOut = 
Simulink.SimulationData.Dataset 'topOut' with 4 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   
    4  [1x1 Signal]      INNERDATA     ...erA|sldemo_mdlref_counter_bus/COUNTER

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

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.

You can use Simulink.SignalData.SignalLoggingInfo objects to programmatically override logging settings for specific signals. For example, you can create a Simulink.SimulationData.SignalLoggingInfo object to override the signal logging settings such that only one of several signals marked for logging is logged.

This example uses a model of a rotating clutch system. In the model, ten signals are marked for logging. For more information about the model, see Building a Clutch Lock-Up Model.

mdl = "sldemo_clutch_override";
open_system(mdl);

You can use a Simulink.SimulationData.SignalLoggingInfo object to log only the VehicleSpeed signal. The VehicleSpeed signal is connected the second output port of the Unlocked subsystem. Create a Simulink.SimulationData.SignalLoggingInfo object for the VehicleSpeed signal by using the BlockPath and OutputPortIndex properties.

blkPath = "sldemo_clutch_override/Unlocked";
portNum = 2;
sigInfo = Simulink.SimulationData.SignalLoggingInfo(blkPath,portNum);

Create an empty Simulink.SimulationData.ModelLoggingInfo object. Then, assign the signal logging override settings sigInfo to the model logging information object.

mdlInfo = Simulink.SimulationData.ModelLoggingInfo(mdl);
mdlInfo.Signals(1) = sigInfo;

Use the verifySignalAndModelPaths function to ensure that you specified valid signal logging settings for the model.

verifiedObj = verifySignalAndModelPaths(mdlInfo)
verifiedObj = 
  ModelLoggingInfo with properties:

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

Apply the model override object settings using the set_param function.

set_param(mdl,'DataLoggingOverride',mdlInfo)

Simulate the model. Verify that VehicleSpeed is the only signal logged by accessing the Simulink.SimulationData.Dataset object sldemo_clutch_output.

sim(mdl);
sldemo_clutch_output
sldemo_clutch_output = 
Simulink.SimulationData.Dataset 'sldemo_clutch_output' with 1 element

                         Name          BlockPath                       
                         ____________  _______________________________ 
    1  [1x1 Signal]      VehicleSpeed  sldemo_clutch_override/Unlocked

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

Version History

Introduced in R2012b