Override Signal Logging Settings - MATLAB & Simulink (original) (raw)
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:
- Override Signal Logging Settings with Signal Logging Selector
- Override Signal Logging Settings Programmatically
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.
- 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.
Tip
To enable the Configure Signals to Log button, select the Signal logging configuration parameter. - Set Logging Mode to
Override signals
.
In the Signal Logging Selector, if you override some signal logging settings and then setLogging Mode toLog 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 toOverride signals
. Using the Signal Logging Selector to override logging for a specific signal does not affect the signal logging indicator for that signal.
Note
TheOverride 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. - 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.
- 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 Box Signal Logging Configuration For the top-level model node, logs all logged signals in the top model.For a Modelblock node, logs all logged signals in the model reference hierarchy for that block. For the top-level model node, disables logging for all logged signals in the top-level model.For aModel block node, disables logging for all signals in the model reference hierarchy for that block. 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.
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 override settings are ignored and the logging settings defined in the model appear in the Signal Logging Selector. 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.
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 aSimulink.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.
- Create Model Logging Override Object with Logged Signals
- Set Logging Mode of Model Logging Override Object
For additional examples, see:
- Log Top-Level and Referenced Models as Specified in Model
- Override Signal Logging Settings for Specific Signal
- Log Subset of Sample Points
Create Model Logging Override Object with Logged Signals
You can create a model logging override object for a model and automatically add each logged signal in the model to that object.
Open the IterativeCounter
project. The project opens the CounterSystem
model at startup. The CounterSystem
model has four signals marked for logging.
openProject("IterativeCounter"); mdl = "CounterSystem"; mdlInfo = Simulink.SimulationData.ModelLoggingInfo.createFromModel(mdl)
mdlInfo = ModelLoggingInfo with properties:
Model: 'CounterSystem'
LoggingMode: 'OverrideSignals'
LogAsSpecifiedByModels: {}
Signals: [1×4 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.
Open the IterativeCounter
project. The project opens the CounterSystem
model at startup. This model contains a Model block that references the CounterAlgorithm
model. In total, four signals are marked for logging. The top model has three signals marked for logging: BatchData
, Controls
, and OuterCount
. The referenced model has one signal marked for logging: InnerCount
.
openProject("IterativeCounter"); mdl = 'CounterSystem'; mdlInner = 'CounterSystem/Model';
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)
innerLogMode = getLogAsSpecifiedInModel(mdlInfo,mdlInner)
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); out1 = sim(mdl); out1.logsout
ans = Simulink.SimulationData.Dataset 'logsout' with 3 elements
Name BlockPath
__________ _________________________
1 [1x1 Signal] BatchData CounterSystem/Concatenate
2 [1x1 Signal] OuterCount CounterSystem/Model
3 [1x1 Signal] Controls CounterSystem/Subsystem
- 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)
innerLogMode = getLogAsSpecifiedInModel(mdlInfo,mdlInner)
Apply the model override object settings. Then, simulate the model. This time, the software logs only the InnerCount
signal.
set_param(mdl,DataLoggingOverride=mdlInfo); out2 = sim(mdl); out2.logsout
ans = Simulink.SimulationData.Dataset 'logsout' with 1 element
Name BlockPath
__________ ________________________________________
1 [1x1 Signal] InnerCount ...l|CounterAlgorithm/For Each Subsystem
- Use braces { } to access, modify, or add elements using index.
See Also
Objects
- Simulink.SimulationData.ModelLoggingInfo | Simulink.SimulationData.SignalLoggingInfo | Simulink.SimulationData.LoggingInfo