Is it possible to convert Simulink.S​imulationD​ata.Datase​t signals into individual array variables?

4 views (last 30 days)
When exporting Simulink Simulation data to .mat files, the data is stored as a Simulink.SimulationData.Dataset class which houses all the recorded signals (of class Simulink.SimulationData.Signal). Is it possible to extract all of the signal value data into new array variables with the same signal names?
For examples, DS (1x1 dataset) contains the two signals:
speed (1x1 signal)
command (1x1 signal)
Then I’d like to programmatically create the following variables in my workspace from DS where each variable contains only their data values:
Speed (100x1 double)
Command (100x1 double)

Answers (1)

ag
ag on 7 Nov 2024 at 11:01
Hi Mark,
To extract values from a "Simulink.SimulationData.Signal" into array variables, you can iterate over the signals in the dataset and dynamically create variables using the "matlab.lang.makeValidName" function. You can then assign the respective values using the "assignin" function.
The following code snippet demonstrates this process:
% Loop through each element in the dataset
for i = 1:numElements(DataSet)
signal = DataSet.get(i);
signalName = signal.Name;
signalDataArray = signal.Values.Data;
% Create a valid variable name and assign the data to the base workspace
varName = matlab.lang.makeValidName(signalName);
assignin('base', varName, signalDataArray);
end
For more details, please refer to the following MathWorks documentations:
Hope this helps!

Categories

Find more on Save Run-Time Data from Simulation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!