Documentation

Enable Signal Logging for a Model

Enable and Disable Logging at the Model Level

To log a signal, mark it for signal logging. For details, see Configure a Signal for Logging.

Enable or disable logging globally for all signals that you mark for signal logging in a model. By default, signal logging is enabled. Simulink® logs signals only if Configuration Parameters > Data Import/Export > Signal logging parameter is checked. If the option is not checked, Simulink ignores the signal logging settings for individual signals.

To disable signal logging, use one of these approaches.

  • Clear the Configuration Parameters > Data Import/Export > Signal logging parameter.

  • Use the SignalLogging parameter. For example:

    set_param(bdroot,'SignalLogging','off')

Selecting a Subset of Signals to Log

You can select a subset of signals to log for a model that has:

  • Signal logging enabled

  • Logged signals

For details, see Override Signal Logging Settings.

Migrate Scripts That Use ModelDataLogs API

For scripts that simulate a model created in a release earlier than R2016a that uses ModelDataLogs format for logging, update the code to log in Dataset format.

If you have already logged signal data in the ModelDataLogs format, you can use the Simulink.ModelDataLogs.convertToDataset function to update the ModelDataLogs signal logging data to use Dataset format. For example, to update the older_model_dataset from ModelDataLogs format to Dataset format:

new_dataset = logsout.convertToDataset('older_model_data')

Converting a model from using ModelDataLogs format to using Dataset format can require that you modify your existing models and to code in callbacks, functions, scripts, or tests. The following table identifies possible issues to address after converting to Dataset format. The table provides solutions for each issue.

Possible Issue After Conversion to Dataset FormatSolution

Code in existing callbacks, functions, scripts, or tests that used the ModelDataLogs programmatic interface to access data can result in an error.

Check for code that uses ModelDataLogs format access methods. Update that code to use Dataset format access methods.

For example, suppose that existing code includes the following line:

logsout.('Subsystem Name').X.data

Replace that code with a Dataset access method:

logsout.getElement('x').Values.data

Logging bus signals requires a configuration parameter change.

Logging buses in Dataset format requires that Configuration Parameters > Diagnostics > Connectivity > Mux blocks used to create bus signals is set to error.

To configure a model for proper bus usage, run the Upgrade Advisor with the Check bus usage check.

Mux block signal names are lost.

The Dataset format treats Mux block signals as a vector.

To identify signals by signal names, replace Mux blocks with a Bus Creator blocks. Set Configuration Parameters > Diagnostics > Connectivity > Mux blocks used to create bus signals to error.

Signal Viewer cannot be used for signal logging.

Simulink does not log signal logging data in the Signal Viewer.

Use the signal logging output variable to view the logged data.

The unpack method generates an error.

The unpack method, which is supported for Simulink.ModelDataLogs and Simulink.SubsysDataLogs objects, is not supported for Simulink.SimulationData.Dataset objects.

For example, if the data in mlog has three fields: x, y, and z, then:

  • For ModelDataLogs format data, the mlog.unpack method creates three variables in the base workspace.

  • For Dataset format data, access methods by names. For example:

    x = logsout.getElement('x').Values

The ModelDataLogs and Dataset formats have different naming rules for unnamed signals.

If necessary, add signal names.

  • In ModelDataLogs format, for an unnamed signal coming from a block, Simulink assigns a name in this form:

    SL_BlockName+<portIndex>

    For example, SL_Gain1.

  • In Dataset format, elements do not need a name, so Simulink leaves the signal name empty.

  • For both ModelDataLogs and Dataset formats, Simulink assigns the same name to unnamed signals that come from Bus Selector blocks.

Test points in referenced models are not logged.

Consider enabling signal logging for test points in a referenced model.

Script uses who or whos functions.

Consider using Simulink.SimulationData.Dataset.find instead.

Specify a Name for Signal Logging Data

You use the model-level signal logging name to access the signal logging data for a model. The default name for the signal logging data is logsout. Specifying a model-level signal logging name can make it easier to identify the source of the logged data. For example, you could specify the signal logging name car_logsout to identify the data as being the signal logging data for the car model.

To specify a different model-level signal logging name, use either of these approaches:

  • In the edit box next to the Configuration Parameters > Data Import/Export > Signal logging parameter, enter the signal logging name.

  • Use the SignalLoggingName parameter, specifying a signal logging name. For example:

    set_param(bdroot, 'SignalLoggingName', 'heater_model_signals')

Related Examples

Was this topic helpful?