Enable Signal Logging for a Model

Enable and Disable Logging at the Model Level

To log a signal, you must 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.

Specify the Signal Logging Data Format

The signal logging format determines how Simulink stores the logged signal data. You can store the data using either the Dataset or ModelDataLogs format.

Set the Signal Logging Format

To set the signal logging format, use either of these approaches:

  • Set the Configuration Parameters > Data Import/Export > Signal logging format parameter to either Dataset (default) or ModelDataLogs.

  • Use the SignalLoggingSaveFormat parameter, with a value of Dataset or ModelDataLogs. For example:

    set_param(bdroot, 'SignalLoggingSaveFormat', 'Dataset')

Use the Dataset Format for Signal Logging in New Models

Use the Dataset format for signal logging for new models. The ModelDataLogs format is supported for backwards compatibility. The ModelDataLogs format will be removed in a future release.

The Dataset format:

  • Uses MATLAB® timeseries objects to store logged data , which allows you to work with logging data in MATLAB without a Simulink license. For example, to manipulate the logged data, you can use MATLAB timeseries methods such as filter, detrend, and resample.

  • Supports logging multiple data values for a given time step, which can be important for Iterator subsystem and Stateflow® signal logging.

  • Provides an easy to analyze format for logged signal data for models with deep hierarchies, bus signals, and signals with duplicate or invalid names.

  • Supports signal logging in Rapid Accelerator mode.

  • Avoids the limitations of the ModelDataLogs format, which Bug Report 495436 describes.

When you specify the Dataset format, Simulink stores the data using a Simulink.SimulationData.Dataset object.

    Note:   You must use the Dataset format to log arrays of buses.

Migrate from ModelDataLogs to Dataset Format

The ModelDataLogs logging format is supported for backwards compatibility. The ModelDataLogs format will be removed in a future release. To enable existing models that use ModelDataLogs format to continue to work in future releases, migrate those models to use Dataset format.

Use the Upgrade Advisor to upgrade a model to use Dataset format, using one of these approaches:

  • In the Simulink Editor, select Analysis > Model Advisor > Upgrade Advisor

  • From the MATLAB command line, use the upgradeadvisor function.

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 dataset to use Dataset format. For example, to update the older_model_dataset from ModelDataLogs format to Dataset format:

new_dataset = logsout.convertToDataset('older_model_dataset')

Depending upon your particular circumstances, converting a model from using ModelDataLogs format to using Dataset format may require that you make some modifications to your existing models and to code in callbacks, functions, scripts, or tests. The following table identifies possible issues that you may need 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 may 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 existing code includes the following line:

logsout.('Subsystem Name')

Replace that code with a Dataset access method:


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 be 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.

If you need 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.

If you use the Dataset format for signal logging, then Simulink does not log the signals to be logged in the Signal Viewer.

Configure the signal for signal logging.

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 logged data 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:


    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.

Running or updating a model that uses model referencing might return a signal logging format inconsistency error.

Follow the approach described in Model Reference Signal Logging Format Consistency.

Model Reference Signal Logging Format Consistency

If signal logging is enabled for a top model, then the signal logging format for the non-protected referenced models must be the same as the signal logging format for the top model.

Simulink performs signal logging format consistency checking during model update or when you run a simulation. Simulink does not report inconsistencies during code generation for model reference simulation target code.

If Simulink reports a signal logging format inconsistency, then use one of the following approaches:

  • Use the Upgrade Advisor (with the upgradeadvisor function) to upgrade a model to use Dataset format.

  • Use the Simulink.SimulationData.updateDatasetFormatLogging function to convert a model and its referenced models to use Dataset format for signal logging.

  • Turn off signal logging for the model, including for all referenced models, by clearing the Configuration Parameters > Data Import/Export > Signal logging parameter check box.

  • Disable logging for all signals in this top-level Model block.

    1. Select the Configuration Parameters > Data Import/Export > Configure Signals to Log button.

    2. In the Signal Logging Selector dialog box, in the Model Hierarchy pane, clear the check box for the top Model block in the model reference hierarchy.

Specify a Name for the Signal Logging Data for a Model

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')
Was this topic helpful?