Signal logging override settings for a model
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 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 Models | Property Settings |
---|---|
For top model and all referenced models, use logging settings specified in the model. | Set |
For top model and all referenced models, use override signal logging settings. | Set |
For top model and referenced models, use a mix of override signal logging settings and the signal logging settings specified in the model. | Set Include models you want to ignore
override signal logging settings in the |
For more information and examples, see Override Signal Logging Settings from MATLAB.
Name | Description |
---|---|
Signal logging override status | |
Source of signal logging settings for the top model or a top-level Model block | |
All signals that have signal override settings |
Name | Description |
---|---|
Find signals within the | |
Verify signal and model paths for the model signal logging override object. | |
Determine whether the model logs signals as specified in the model or uses override settings. | |
Set the logging mode for the top model or a top-level Model block. | |
Create and populate a model signal logging override object with all logged signals in the model hierarchy. | |
Set signals to log or override logging settings. |
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 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 model or for a given referenced model, use the
setLogAsSpecifiedInModel
method.
character array
RW
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, 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 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.
cell array — For the top model, specify the model name. For Model blocks, specify the block path.
RW
Vector of Simulink.SimulationData.SignalLoggingInfo
objects
for all signals with signal logging override settings.
vector of Simulink.SimulationData.SignalLoggingInfo
objects
RW
Create a Simulink.SimulationData.ModelLoggingInfo
object for a top model,
with override settings for each logged signal in the model.
model_logging_info_object = ... Simulink.SimulationData.ModelLoggingInfo.createFromModel(...model
,options
)
model
Name of the top 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 variants.
AllVariants
— Include logged signals from all
subsystem and model 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.SimulationData.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.
model_logging_override_object
Simulink.SimulationData.ModelLoggingInfo
object for the top
model.
creates
a model_logging_info_object
= Simulink.SimulationData.ModelLoggingInfo.createFromModel(model
)Simulink.SimulationData.ModelLoggingInfo
object
for the model that includes logged signals for the following kinds
of systems:
Libraries
Masked subsystems
Referenced models
Active variants
creates a model_logging_override_object
=
Simulink.SimulationData.ModelLoggingInfo.createFromModel(model
,
options)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
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);
You can use the options for the createFromModel
method to specify
how the method should handle model components like variants and model references. For
example, use the Variants
option to create a
model_logging_override
object that includes logged signals in all
variants of the sldemo_variant_subsystems
model.
By default, the sldemo_variant_subsystems
model does not log any
signals. Start by configuring the output signals from the Linear
Controller
and Nonlinear Controller
subsystems for
logging.
% Open the sldemo_variant_subsystems model sldemo_variant_subsystems; % Mark the output of the Linear Controller subsystem for logging ph = get_param('sldemo_variant_subsystems/Controller/Linear Controller',... 'PortHandles'); set_param(ph.Outport(1),'DataLogging','on'); % Mark the output of the Nonlinear Controller subsystem for logging ph1 = get_param('sldemo_variant_subsystems/Controller/Nonlinear Controller',... 'PortHandles'); set_param(ph1.Outport(1),'DataLogging','on');
Then, use the createFromModel
method to create a
model_logging_override
object that includes signals logged in all
variant subsystems of the sldemo_variant_subsystems
model.
% Create a model_logging_override object for the model including all variants mi = Simulink.SimulationData.ModelLoggingInfo.createFromModel(... 'sldemo_variant_subsystems', 'Variants', 'AllVariants')
mi = ModelLoggingInfo with properties: Model: 'sldemo_variant_subsystems' LoggingMode: 'OverrideSignals' LogAsSpecifiedByModels: {} Signals: [1×2 Simulink.SimulationData.SignalLoggingInfo]
Specify signals to log or override logging settings.
model_logging_override_object = .... Simulink.SimulationData.ModelLoggingInfo(model)
model
Name of the top model for which to create a
Simulink.SimulationData.ModelLoggingInfo
object
model_logging_override_object
Simulink.SimulationData.ModelLoggingInfo
object created for
the specified top model.
creates a model_logging_override_object
=
Simulink.SimulationData.ModelLoggingInfo(model
)Simulink.SimulationData.ModelLoggingInfo
object for the
specified top 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.
The following example shows how to log all signals as specified in the top 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 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);
Find signals within the Signals
vector, using
a block path and optionally an output port index.
signal_indices = ... model_logging_override_object.findSignal(block_path) signal_indices = ... model_logging_override_object.findSignal(... block_path, port_index)
block_path
Source block to search. The block_path
must
be one of the following:
Character vector
Cell array of character vectors
Simulink.BlockPath
object
port_index
Index of the output port to search. Specify a scalar greater
than, or equal to, 1
.
signal_indices
Vector of numeric indices into the signals vector of the Simulink.SimulationData.ModelLoggingInfo
object.
finds
the indices of the signals for the block path that you specify.signal_indices
= model_logging_override_object.findSignal(block_path
)
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 character vector 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.
finds
the indices of the output signal for the port that you specify, for
the block path that you specify.signal_indices
= model_logging_override_object.findSignal(block_path
, port_index
)
Do not use the port_index
argument for Stateflow chart
signals.
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)
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({'ex_bus_logging/CounterA', ... 'ex_mdlref_counter_bus/Bus Creator'})
signal_index = 4
For an example that uses the findSignal
method with a Stateflow chart, see Override Logging Properties with the Command-Line API (Stateflow).
Determine whether the model logs as specified in the model or uses override settings.
logging_mode = ... getLogAsSpecifiedInModel(model_logging_override_object, path)
model_logging_override_object
A Simulink.SimulationData.ModelLoggingInfo
object.
path
The path
is a character vector that specifies
one of the following:
Name of the top model
Block path of a Model block in the top model
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.
returns:logging_mode
= model_logging_override_object.getLogAsSpecifiedInModel(path
)
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.
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
Set logging mode for top model or top-level Model block
setLogAsSpecifiedInModel(override_object, path)
override_object
Simulink.SimulationData.ModelLoggingInfo
object.
path
Character vector that specifies one of the following:
Name of the top model
Block path of a Model block in the top 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.
setLogAsSpecifiedInModel(
sets the LoggingMode property for a top model or a Model block in the top model.override_object
, path
, value
)
The following example shows how to log only signals in the top model, using the logging settings specified in that model:
sldemo_mdlref_bus; mi = Simulink.SimulationData.ModelLoggingInfo('sldemo_mdlref_bus'); mi.LoggingMode = 'OverrideSignals'; mi = setLogAsSpecifiedInModel(mi, 'sldemo_mdlref_bus', true); set_param('sldemo_mdlref_bus', 'DataLoggingOverride', mi);
Verify paths in Simulink.SimulationData.ModelLoggingInfo
object.
verified_object = verifySignalAndModelPaths... (model_logging_override_object, action)
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.
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.
verified_object
= verifySignalAndModelPaths(model_logging_override_object
, action
)
For a Simulink.SimulationData.ModelLoggingInfo
object,
verify that:
All character vectors in the LogAsSpecifiedByModels
property
are either the name of the top model or the block path of a Model block in the top
model.
The block paths for signals in the Signals
property refer to
valid blocks within the hierarchy of the top 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.
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')
Simulink.BlockPath
| Simulink.SimulationData.DataStoreMemory
| Simulink.SimulationData.LoggingInfo
| Simulink.SimulationData.Signal
| Simulink.SimulationData.SignalLoggingInfo