Simulink.SimulationData.ModelLoggingInfo

Signal logging override settings for a model

Description

This class is a collection of Simulink.SimulationData.SignalLoggingInfo objects that specify all signal logging override settings for a model.

Use methods and properties of this class to:

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

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

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. Use the LoggingMode and LogAsSpecifiedByModels properties to control which logging settings to apply.

Logging Mode for ModelsProperty Settings

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

Set LoggingMode to LogAllAsSpecifiedInModel.

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

Set LoggingMode to OverrideSignals.

For top-level 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.

In the LogAsSpecifiedByModels cell array, include the models that you do not want to use the override signal logging settings.

For more information and examples, see Override Signal Logging Settings from MATLAB.

Property Summary

Name

Description

LoggingMode

Signal logging override status

LogAsSpecifiedByModels

Source of signal logging settings for the top-level model or a top-level Model block

Signals

All signals that have signal override settings

Method Summary

Name

Description

findSignal

Find signals within the Signals vector, using block path and output port index.

verifySignalAndModelPaths

Verify signal and model paths for the model signal logging override object.

getLogAsSpecifiedInModel

Determine whether the model logs signals as specified in the model or uses override settings.

setLogAsSpecifiedInModel

Set the logging mode for the top-level model or a top-level Model block.

createFromModel

Create and populate a model signal logging override object with all logged signals in the model reference hierarchy.

ModelLoggingInfo

Set signals to log or override logging settings.

Properties

LoggingMode

Description

Signal logging override status. Values are:

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

    • true — Logs all signals, as specified in the model.

    • false — Logs only the signals specified in the Signals property.

  • LogAllAsSpecifiedInModel — Logs signals in the top-level 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 the top-level model or for a given reference model, use the setLogAsSpecifiedInModel method.

Data Type

logical value — true or false

Access

RW

LogAsSpecifiedByModels

Description

When LoggingMode is set to 'OverrideSignals', this cell array specifies whether the top-level model or a top-level Model block logs all signals based on the signal logging settings defined in the model.

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

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

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

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

Data Type

cell array — For the top-level model, specify the model name. For Model blocks, specify the block path.

Access

RW

Signals

Description

Vector of Simulink.SimulationData.SignalLoggingInfo objects for all signals with signal logging override settings.

Data Type

vector of Simulink.SimulationData.SignalLoggingInfo objects

Access

RW

Methods

createFromModel

Purpose

Create a Simulink.SimulationData.ModelLoggingInfo object for a top-level model, with override settings for each logged signal in the model.

Syntax

model_logging_info_object = ...
Simulink.SimulationData.ModelLoggingInfo.createFromModel(...
model, options)

Input Arguments

model

Name of the top-level model for which to create a Simulink.SimulationData.ModelLoggingInfo object.

options

You can use any combination of the following option name and value pairs to control the kinds of systems from which to include logged signals.

  • FollowLinks

    • on — (Default) Include logged signals from inside of libraries.

    • off — Skip all libraries.

  • LookUnderMasks

    • all — (Default) Include logged signals from all masked subsystems.

    • none — Skip all masked subsystems.

    • graphical — Include logged signals from masked subsystems that do not have a workspace or dialog box.

    • functional — Include logged signals from masked subsystems that do not have a dialog box.

  • Variants

    • ActiveVariants — (Default) Include logged signals from only active subsystem and model reference variants.

    • AllVariants — Include logged signals from all subsystem and model reference variants.

  • RefModels

    • on — (Default) Include logged signals from referenced models.

    • off — Skip all referenced models.

If you select more than one option, then the created Simulink.SimlationData.ModelLoggingInfo object includes signals that fit the combinations (the "AND") of the specified options. For example, if you set FollowLinks to on and set RefModels to off, then the model signal logging override object does not include signals from library links that exist inside of referenced models.

Output Arguments

model_logging_override_object

Simulink.SimulationData.ModelLoggingInfo object for the top-level model.

Description

model_logging_info_object = Simulink.SimulationData.ModelLoggingInfo.createFromModel(model) creates a Simulink.SimulationData.ModelLoggingInfo object for the model that includes logged signals for the following kinds of systems:

  • Libraries

  • Masked subsystems

  • Referenced models

  • Active variants

model_logging_override_object = Simulink.SimulationData.ModelLoggingInfo.createFromModel(model, options) creates a Simulink.SimulationData.ModelLoggingInfo object for the model. The included logged signals reflect the options settings for the following kinds of systems:

  • Libraries

  • Masked subsystems

  • Referenced models

  • Variants

Examples

The following example creates a model logging override object for the sldemo_mdlref_bus model and automatically adds each logged signal in the model to that object:

mi = Simulink.SimulationData.ModelLoggingInfo.createFromModel(...
'sldemo_mdlref_bus')
mi = 

  ModelLoggingInfo with properties:

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

To apply the model override object settings, use:

set_param(sldemo_mdlref_bus, 'DataLoggingOverride', mi);

The following example explicitly specifies the kinds of systems from which to include signals, rather than use the default settings for each kind of system. This example specifies to include signals from all model reference variants (instead of using the default of including only active variant).

The sldemo_mdlref_variants model has two variants: sldemo_mrv_nonlinear_controller and sldemo_controller. In this example, in each variant, you configure a signal for signal logging, and then create a Simulink.SimulationData.ModelLoggingInfo object. The resulting object includes, in the Signals property, two signals (one from each variant).

sldemo_mrv_nonlinear_controller;
sldemo_mrv_second_order_controller;
ph = get_param('sldemo_mrv_nonlinear_controller/Add','PortHandles');
set_param(ph.Outport(1),'DataLogging','on');
ph1 = get_param('sldemo_mrv_second_order_controller/Add','PortHandles');
set_param(ph1.Outport(1),'DataLogging','on');
mi = Simulink.SimulationData.ModelLoggingInfo.createFromModel(...
'sldemo_mdlref_variants', 'Variants', 'AllVariants')

Results:

V_NONLINEAR_CONTROLLER =
 
Simulink.Variant
    Condition: 'CTRL==1'

 
V_SECOND_ORDER_CONTROLLER =
 
Simulink.Variant
    Condition: 'CTRL==2'


CTRL =

     1

mi = 

  Simulink.SimulationData.ModelLoggingInfo
  Package: Simulink.SimulationData

  Properties:
                     Model: 'sldemo_mdlref_variants'
               LoggingMode: 'OverrideSignals'
    LogAsSpecifiedByModels: {}
                   Signals: [1x2 Simulink.SimulationData.SignalLoggingInfo]

   Methods

ModelLoggingInfo

Purpose

Specify signals to log or override logging settings.

Syntax

model_logging_override_object = ....
Simulink.SimulationData.ModelLoggingInfo(model)

Input Arguments

model

Name of the top-level model for which to create a Simulink.SimulationData.ModelLoggingInfo object

Output Arguments

model_logging_override_object

Simulink.SimulationData.ModelLoggingInfo object created for the specified top-level model.

Description

model_logging_override_object= Simulink.SimulationData.ModelLoggingInfo(model) creates a Simulink.SimulationData.ModelLoggingInfo object for the specified top-level model.

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 method with the Simulink.SimulationData.ModelLoggingInfo object for the model.

Examples

The following example shows how to log all signals as specified in the top-level model and all referenced models.

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

  ModelLoggingInfo with properties:

                     Model: 'sldemo_mdlref_bus'
               LoggingMode: 'LogAllAsSpecifiedInModel'
    LogAsSpecifiedByModels: {}
                   Signals: []

To apply the model override object settings, use:

set_param(sldemo_mdlref_bus, 'DataLoggingOverride', mi);

The following example shows how to log only signals in the top-level model:

mi = ...
Simulink.SimulationData.ModelLoggingInfo('sldemo_mdlref_bus');
mi.LoggingMode = 'OverrideSignals';
mi = mi.setLogAsSpecifiedInModel('sldemo_mdlref_bus', true); 
set_param('sldemo_mdlref_bus', 'DataLoggingOverride', mi);

findSignal

Purpose

Find signals within the Signals vector, using a block path and optionally an output port index.

Syntax

signal_indices = ...
      model_logging_override_object.findSignal(block_path)
signal_indices = ...
      model_logging_override_object.findSignal(...
      block_path, port_index)

Input Arguments

block_path

Source block to search. The block_path must be one of the following:

  • String

  • Cell array of strings

  • Simulink.BlockPath object

port_index

Index of the output port to search. Specify a scalar greater than, or equal to, 1.

Output Arguments

signal_indices

Vector of numeric indices into the signals vector of the Simulink.SimulationData.ModelLoggingInfo object.

Description

signal_indices = model_logging_override_object.findSignal(block_path) finds the indices of the signals for the block path that you specify.

To find a single instance of a signal within a referenced model, use a Simulink.BlockPath object or a cell array with a full path.

To find all instances of a signal within a referenced model, use a string with the relative path of the signal within the referenced model.

To find a logged chart signal within a Stateflow® chart, use a Simulink.BlockPath object and set the SubPath property to the name of the Stateflow chart signal.

signal_indices = model_logging_override_object.findSignal(block_path, port_index) finds the indices of the output signal for the port that you specify, for the block path that you specify.

Do not use the port_index argument for Stateflow chart signals.

Examples

To find a signal that is not in a Stateflow chart and that does not appear in multiple instances of a referenced model:

open_system(docpath(fullfile(docroot,'toolbox','simulink','examples','ex_bus_logging')))
% Open the referenced model
ex_mdlref_counter_bus
mi = Simulink.SimulationData.ModelLoggingInfo.createFromModel(... 
     'ex_bus_logging');
% Click the COUNTERBUSCreator block that is the source of 
% the logged COUNTERBUS signal
signal_index = mi.findSignal(gcb)

The output is:

signal_index =

     1

To find a signal in a specific instance of a referenced model that is not in a Stateflow chart, use the following approach:

signal_index = mi.findSignal({'sldemo_mdlref_bus/CounterA', ...
'sldemo_mdlref_counter_bus/Bus Creator'})

For an example that uses the findSignal method with a Stateflow chart, see Override Logging Properties with the Command-Line API in the Stateflow documentation.

getLogAsSpecifiedInModel

Purpose

Determine whether the model logs as specified in the model or uses override settings.

Syntax

logging_mode = ...
getLogAsSpecifiedInModel(model_logging_override_object, path)

Input Arguments

model_logging_override_object

A Simulink.SimulationData.ModelLoggingInfo object.

path

The path is a string that specifies one of the following:

  • Name of the top-level model

  • Block path of a Model block in the top-level model

Output Arguments

logging_mode

The logging_mode is:

  • true, if the model specified by path is logged as specified in the model.

  • false, if the model specified by path is logged using the override settings specified in the Signals property.

Description

logging_mode = model_logging_override_object.getLogAsSpecifiedInModel(path) returns:

  • true, if the model specified by path is logged as specified in the model.

  • false, if the model specified by path is logged using the override settings specified in the Signals property.

Examples

In the following example, the Simulink.SimulationData.ModelLoggingInfo object mi uses the override settings specified in its Signals property.

mi = Simulink.SimulationData.ModelLoggingInfo('sldemo_mdlref_bus');
logging_mode = getLogAsSpecifiedInModel(mi, 'sldemo_mdlref_bus')
logging_mode =

     0

setLogAsSpecifiedInModel

Purpose

Set logging mode for top-level model or top-level Model block

Syntax

setLogAsSpecifiedInModel(override_object, path)

Input Arguments

override_object

Simulink.SimulationData.ModelLoggingInfo object.

path

String that specifies one of the following:

  • Name of the top-level model

  • Block path of a Model block in the top-level model

value

Logging mode:

  • true, if the model specified by path is logged as specified in the model

  • false, if the model specified by path is logged using the override settings specified in the Signals property.

Description

setLogAsSpecifiedInModel(override_object, path, value) sets the LoggingMode property for a top-level model or a Model block in the top-level model.

Example

The following example shows how to log only signals in the top-level model, using the logging settings specified in that model:

sldemo_mdlref_bus;
mi = Simulink.SimulationData.ModelLoggingInfo('sldemo_mdlref_bus');
mi.LoggingMode = 'OverrideSignals';
setLogAsSpecifiedInModel(mi, 'sldemo_mdlref_bus', true); 
set_param('sldemo_mdlref_bus', 'DataLoggingOverride', mi);

verifySignalAndModelPaths

Purpose

Verify paths in Simulink.SimulationData.ModelLoggingInfo object.

Syntax

verified_object = verifySignalAndModelPaths...
     (model_logging_override_object, action)

Input Arguments

model_logging_override_object

The Simulink.SimulationData.ModelLoggingInfo object to verify. This argument is required.

action

The action that the function performs if verification fails. This argument is optional. Specify one of the following values:

  • error — (default) Throw an error when verification fails

  • warnAndRemove — Issue a warning when verification fails and update the Simulink.SimulationData.ModelLoggingInfo object.

  • remove — Silently update the Simulink.SimulationData.ModelLoggingInfo object.

Output Arguments

verified_object

If the method detects no invalid paths, it returns the validated object. For example:

verified_object = 

  Simulink.SimulationData.ModelLoggingInfo
  Package: Simulink.SimulationData

  Properties:
                     Model: 'logging_top'
               LoggingMode: 'OverrideSignals'
    LogAsSpecifiedByModels: {}
                   Signals: [1x11 Simulink.SimulationData.SignalLoggingInfo]

If the method detects an invalid path, it performs the action specified by the action argument. By default, it issues an error message.

Description

verified_object = verifySignalAndModelPaths(model_logging_override_object, action)

For a Simulink.SimulationData.ModelLoggingInfo object, verify that:

  • All strings in the LogAsSpecifiedByModels property are either the name of the top-level model or the block path of a Model block in the top-level model.

  • The block paths for signals in the Signals property refer to valid blocks within the hierarchy of the top-level model.

  • The OutputPortIndex property for all signals in the Signals property are valid for the given block.

  • All signals in the Signals property refer to logged signals.

The action argument specifies what action the method performs. By default, the method returns an error if it detects an invalid path.

If you use the Simulink.SimulationData.ModelLoggingInfo constructor and specify a Simulink.SimulationData.SignalLoggingInfo object for each signal, then consider using the verifySignalAndModelPaths method to verify that your object definitions are valid.

Example

The following example shows how to validate the signal and block paths in a Simulink.SimulationData.ModelLoggingInfo object. Because the action argument is warnAndRemove, if the validation fails, the verifySignalAndModelPaths method issues a warning and updates the Simulink.SimulationData.ModelLoggingInfo object.

mi = Simulink.SimulationData.ModelLoggingInfo('sldemo_mdlref_bus');
verified_object = verifySignalAndModelPaths...
     (mi, 'warnAndRemove')
Was this topic helpful?