Managing Simulation Data Collections with Simulink.SimulationData.Dataset

The Simulink.SimulationData.Dataset class serves as a container for grouping simulation data, whether retrieving logged results or defining external inputs.

Construction Syntax

Instances can be initialized in three primary ways:

  1. obj = Simulink.SimulationData.Dataset: Generates an empty container.
  2. obj = Simulink.SimulationData.Dataset(sourceData): Populates the container using existing data structures.
  3. obj = Simulink.SimulationData.Dataset(sourceData, "DatasetName", label): Initializes with data and assigns a specific identifier.

Retrieving Logged Simulation Results

To extract data recorded during execution, consider the vdp reference model.

modelRef = 'vdp';
open_system(modelRef);
runOutput = sim(modelRef, 'SaveState', 'on');

The variable runOutput holds a Simulink.SimulationOutput object. Within this object, logged signals are stored in the yout property as a Dataset.

loggedSignals = runOutput.yout;

Individual signals within the Dataset are stored as Simulink.SimulationData.Signal objects. Access specific signals using their registered name or index position.

signalObj = loggedSignals.getElement('x1');
timeSeriesData = signalObj.Values;

The underlying numeric values and time vectors reside within the Data and Time properties of the timeseries object.

yValues = timeSeriesData.Data;
tValues = timeSeriesData.Time;

These operations can be chained for concise access:

directData = runOutput.yout.getElement('x1').Values.Data;

Constructing Input Signal Collections

Dataset objects are also required when feeding external data into root-level Inport blocks. The following workflow generates three distinct waveforms and bundles them.

dt = 0.01;
steps = 1001;
tVector = (0:steps-1)' * dt;

% Define waveforms
sigA = sin(2*pi*0.5*tVector);
sigB = square(2*pi*0.5*tVector);
sigC = tVector;

% Wrap in timeseries objects
tsA = timeseries(sigA, tVector, 'Name', 'SineInput');
tsB = timeseries(sigB, tVector, 'Name', 'SquareInput');
tsC = timeseries(sigC, tVector, 'Name', 'RampInput');

Initialize the Dataset and populate it using addElement.

inputBundle = Simulink.SimulationData.Dataset;
inputBundle.Name = 'ModelInputs';
inputBundle = addElement(inputBundle, tsA);
inputBundle = addElement(inputBundle, tsB);
inputBundle = addElement(inputBundle, tsC);

Configure the model InputLoaderModel to use this variable in the Configuration Parameters under Data Import/Export.

open_system('InputLoaderModel.slx');
simResult = sim('InputLoaderModel.slx');

The order of elements in the Dataset dictates mapping to Inport blocks. Modifying the order changes the signal assignment.

% Swap second and third elements
temp = inputBundle{2};
inputBundle{2} = inputBundle{3};
inputBundle{3} = temp;

Re-running the simulation reflects these changes in the connected scopes.

Data Organization and Storage

When simulation data is logged via Scope blocks, Signal Logging, or To Workspace blocks, the result is typically organized into a Dataset. Elements within the container vary by type:

  • Signals and Outputs: Simulink.SimulationData.Signal
  • States: Simulink.SimulationData.State
  • Data Stores: Simulink.SimulationData.DataStoreMemory

For input preparation, elements may represent signals, buses, or bus arrays. Data can be sourced from various formats, including timeseries objects.

Workflow Recommendations

  • Creation: Use addElement on an empty object, utilize createInputDataset for automatic Inport mapping, or edit interactively via Signal Editor.
  • Access: Use curly braces {} for index-based manipulation. Use getElement, addElement, and setElement for name-based operations.
  • Mapping: The Root Inport Mapper tool facilitates binding Dataset elements to blocks based on path, name, or port order.
  • Large Data: For datasets exceeding memory limits, save to Version 7.3 MAT-files. Consider Simulink.SimulationData.DatasetRef to reference external files without loading full contents into workspace memory.
  • Compatibility: Use the standard save function for backward compatibility rather than export utilities when targeting earlier releases.
  • Custom Import: Implement readers using Simulink.io.FileType to populate Dataset objects from proprietary file formats.

Tags: MATLAB Simulink SimulationData Dataset modeling

Posted on Sun, 07 Jun 2026 18:04:21 +0000 by davelr459