- matlab.lang.makeValidName - https://www.mathworks.com/help/matlab/ref/matlab.lang.makevalidname.html
- assignin - https://www.mathworks.com/help/matlab/ref/assignin.html
Is it possible to convert Simulink.SimulationData.Dataset signals into individual array variables?
4 次查看(过去 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)
0 个评论
回答(1 个)
ag
2024-11-7,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!
0 个评论
另请参阅
类别
在 Help Center 和 File 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!