Container for signal data logs of a model


    Note:   The ModelDataLogs format is supported for backwards compatibility. The ModelDataLogs format will be removed in a future release. For an existing model that uses the ModelDataLogs format, you should migrate the model to use Dataset format. For details, see Migrate from ModelDataLogs to Dataset Format.

    For new models, use the Dataset logging format, which stores logged data in Simulink.SimulationData.Dataset objects.

If you set Configuration Parameters > Data Import/Export > Signal logging format to ModelDataLogs, Simulink® software creates instances of the Simulink.ModelDataLogs class to contain signal logs that it creates while simulating a model (see Signal Logging). Simulink software creates an instance of this class for a top model and for each model referenced by the top model that contains signals to be logged. Simulink software assigns 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

  • For a scope viewer data log, the name specified on the parameter dialog box of the viewer

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 simulation of this model, the MATLAB® workspace contains the following variable:

>> logsout
logsout =
Simulink.ModelDataLogs (siglgex):
  Name                   elements  Simulink Class

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

The logsout variable contains the signal data logged during the simulation. You can use fully qualified object names or the Simulink unpack command to access the signal data stored in logsout. For example, to access the amplitudes of the clk signal in the Delayed Out subsystem, enter

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


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

You can use a custom logging name or signal name when logging a signal. If you use the signal name, and that name occupies more than one line, include an sprintf('\n') between the lines of the signal name when accessing the logged data. For example, to access the signal in the following model:

Use the following syntax:

logsout.(['scope' sprintf('\n') '(delayed out)'])

Programmatically Access Logged Signal Data Saved in ModelDataLogs Format

When you use the ModelDataLogs signal logging format, Simulink saves the logging data in a Simulink.ModelDataLogs object. For information on extracting signal data from that object, see Simulink.ModelDataLogs. 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
Scope block in a modelSimulink.ScopeDataLogs
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: 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

You can log bus signals. When you use ModelDataLogs signal logging format, Simulink 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.

Was this topic helpful?