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

조회 수: 3 (최근 30일)
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)

답변 (1개)

ag
ag 2024년 11월 7일
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!

카테고리

Help CenterFile Exchange에서 Save Run-Time Data from Simulation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by