Dataset Conversion for Logged Data

Why Convert to Dataset Format?

You can use the Simulink.SimulationData.Dataset constructor to convert a MATLAB® workspace variable that contains data that was logged in one of these formats to Dataset format:

  • Array

  • Structure

  • Structure with time

  • MATLAB timeseries

  • ModelDataLogs

Converting data from other Simulink® logging formats to Dataset format simplifies writing scripts to post-process data logged. For example, a model with multiple To Workspace blocks can use different data formats. Converting the logged data to Dataset format avoids the need to write special code to handle different formats.

Different simulation modes have different levels of support for data logging formats. Switching between normal and accelerator modes can require changes to the logging formats used.

The conversion to Dataset format also makes it easier to take advantage of features that require Dataset format. You can easily convert data logged in earlier releases that used a format other than Dataset to work well with Dataset data in a more recent 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 time-series methods such as filter, detrend, and resample.

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

By default, the resulting Dataset object uses the variable name as its name. You can use a name-value pair to specify a Dataset name.

You can use the concat method to combine Dataset objects into one concatenated Dataset object.

Results of Conversion

Dataset objects hold data as elements. To display the elements of a Dataset variable, enter the variable name at the MATLAB command prompt. The elements of Dataset objects are different types, depending on the data they store. For example, signal logging stores data as Simulink.SimulationData.Signal elements and state logging in Dataset format stores data as Simulink.SimulationData.State elements. Each element holds data as a MATLAB time-series object. At conversion, the elements and time-series field populate as much as possible from the converted object.

FormatConversion Result Notes

MATLAB time series

If you log nonbus data, during conversion, the software first adds the data as a Simulink.SimulationData.Signal object. It then adds that object as an element of the newly created Dataset.

If you log bus data in time-series format, one time series corresponds to each element of a bus. Converting arranges the logged data as a structure with time-series objects as leaf nodes. This structure hierarchy matches the bus hierarchy. Conversion of this type of structure of time-series objects adds the whole structure to a Simulink.SimulationData.Signal object. It then adds that object as an element of the data set.

Time-series objects hold relevant information such as block path and timestamps. The conversion tries to preserve this information.

Structure and structure with time

Structure and structure with time formats do not always contain as much information as if you log in Dataset format. However, before converting structure and structure with time formats, the data structure must have time and signals fields.

Conversion populates a Simulink.SimulationData.Signal object with the structure and adds it as an element of the data set. If other information is available, converting also adds it to the element or time-series values. For example, if the structure has a field called blockName, converting adds it to the block path. Otherwise, the block path is empty.

When scope data is logged in structure format, the logged structure has a PlotStyle field. The software uses this field to set the interpolation in the Dataset object.

Array

Arrays contain little information. For example, there is no block path information.

Conversion adds the array to a Simulink.SimulationData.Signal object and adds it as an element of the Dataset object. The conversion leaves unavailable information such as block path and timestamp fields as either empty or with default values.

ModelDataLogs

Converts data from ModelDataLogs format to Dataset format.

Note

The ModelDataLogs format is no longer used for signal logging.

Dataset Conversion Limitations

  • Converting logged data to Dataset format results in a Dataset object that contains all the information that the original logged data included. However, if there is no corresponding information for the other Dataset properties, the conversion uses default values for that information.

  • To log variable-size signals, use the To Workspace block. If you convert data logged with To Workspace to be Dataset format, you lose the information about the variable-size signals.

  • When you log a bus signal in array, structure, or structure with time formats, the logged data is organized with:

    • The first column containing the data for the first signal in the bus

    • The second column containing data for the second bus signal, and so on

    When you convert that data to Dataset, the Dataset preserves that organization. But if you log the bus signal in Dataset format without conversion, the conversion captures the bus data as a structure of time-series objects.

  • If the logged data does not include a time vector, when you convert that data to Dataset, the conversion inserts a time vector. There is one time step for each data value. However, the simulation time steps and the Dataset time steps can vary.

  • Dataset format ignores the specification of frame signals. Conversion of structure or structure with time data to Dataset reshapes the data for logged frame signals.

See Also

Related Topics