- 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?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
ag
el 7 de Nov. de 2024
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 comentarios
Ver también
Categorías
Más información sobre Save Run-Time Data from Simulation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!