Container for signal data logs of a model


    Note:   The ModelDataLogs class is supported for backwards compatibility. Starting in R2016a, you cannot log data in the ModelDataLogs format. Signal logging uses the Dataset format. In R2016a or later, when you open a model from an earlier release that had used ModelDataLogs format, the model simulated in use Dataset format.

    You can convert signal logging data from ModelDataLogs to Dataset format. Converting to Dataset format makes it easier to post-process with other logged data (for example, logged states), which can also use Dataset format. For more information, see Convert Logged Data to Dataset Format.

    If you have legacy code that uses the ModelDataLogs API, you can encounter situations that require updates to your code or model. See Migrate Scripts That Use ModelDataLogs API.

In releases before R2016a, if you set Configuration Parameters > Data Import/Export > Signal logging format to ModelDataLogs, Simulink® software created instances of the Simulink.ModelDataLogs class to contain signal logs while simulating a model. Logging created an instance of this class for a top model and for each model referenced by the top model that contains signals to be logged. Logging assigned the ModelDataLogs object for the top model to a variable in the base workspace. The name of the variable is the name specified in the Configuration Parameters > Data Import/export > Signal logging name parameter. The default value is logsout.

A ModelDataLogs object has a variable number of properties. The first property, named Name, specifies the name of the model whose signal data the object contains or, if the model is a referenced model, the name of the Model block that references the model. The remaining properties reference objects that contain signal data logged during simulation of the model. The objects may be instances of any of the following types of objects:

The names of the properties identify the data being logged as follows:

  • For signal data logs, the name of the signal

  • For a subsystem or model log container, the name of the subsystem or model, respectively

Consider, for example, the following model.

As indicated by the testpoint icons, this model specifies that Simulink software should log the signals named step and scope in the root system and the signal named clk in the subsystem named Delayed Out. After you simulate this model in a release earlier than R2016a, the MATLAB® workspace contains the following variable:

Simulink.ModelDataLogs (siglgex):
  Name                   elements  Simulink Class

  scope                     2      TsArray
  step                      1      Timeseries
  ('Delayed Out')           2      SubsysDataLogs

You can use fully qualified object names or the Simulink unpack command to access the signal data. For example, to access the amplitudes of the clk signal in the Delayed Out subsystem in a logsout object, enter

data = logsout.('Delayed Out').clk.Data;


>> logsout.unpack('all');
>> data = clk.Data;

Access Logged Signal Data Saved in ModelDataLogs Format

The Simulink.ModelDataLogs object contains signal data objects to capture signal logging information for specific model elements.

Model ElementSignal Data Object
Top-level or referenced modelSimulink.ModelDataLogs
Subsystem in a modelSimulink.SubsysDataLogs
Signal other than a bus or Mux signalSimulink.Timeseries
Bus signal or Mux signalSimulink.TsArray

Handling Spaces and Newlines in Logged Names

Signal names in data logs can have spaces or newlines in their names when the signal:

  • Is named and the name includes a space or newline character.

  • Is unnamed and originates in a block whose name includes a space or newline character.

  • Exists in a subsystem or referenced model, and the name of the subsystem, Model block, or of any superior block includes a space or newline character.

The following model shows a signal whose name contains a space, a signal whose name contains a newline, and an unnamed signal that originates in a block whose name contains a newline:

The following example shows how to handle spaces or new lines in logged names, if a model uses ModelDataLogs for the signal logging format.

logsout =
Simulink.ModelDataLogs (model_name):
  Name                   Elements  Simulink Class

  ('x y')                   1      Timeseries
b')                   1      Timeseries
Wave1')         1      Timeseries

You cannot access any of the Simulink.Timeseries objects in this log using TAB name completion or by typing the name to MATLAB. This syntax is not recognized because the space or newline in each name appears to the MATLAB parser as a separator between identifiers. For example:

logsout.x y
??? logsout.x y
Error: Unexpected MATLAB expression.

To reference a Simulink.Timeseries object whose name contains a space, enclose the element containing the space in single quotes:

logsout.('x y')
       Name: 'x y'
     BlockPath: 'model_name/Sine'
     PortIndex: 1
    SignalName: 'x y'
    ParentName: 'x y'
      TimeInfo: [1x1 Simulink.TimeInfo]
          Time: [51x1 double]
          Data: [51x1 double]

To reference a Simulink.Timeseries object whose name contains a newline, concatenate to construct the element containing the newline:

logsout.(['a' cr 'b'])

The same techniques work when a space or newline in a data log derives from the name of:

  • An unnamed logged signal's originating block

  • A subsystem or Model block that contains any logged signal

  • Any block that is superior to such a block in the model hierarchy

This code can reference logged data for the signal:

logsout.(['SL_Sine' cr 'Wave1'])

For names with multiple spaces, newlines, or both, repeat and combine the two techniques as needed to specify the intended name to MATLAB.

Bus Signals

ModelDataLogs format stores each logged bus signal data in a separate Simulink.TsArray object.

The hierarchy of a bus signal is preserved in the logged signal data. The logged name of a signal in a virtual bus derives from the name of the source signal. The logged name of a signal in a nonvirtual bus derives from the applicable bus object, and can differ from the name of the source signal. See Composite Signals for information about those capabilities.

Introduced before R2006a

Was this topic helpful?