0
votes

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)

My initial thought was to write a script to create new variables in a for loop. Something like the following:

NumDatasetElements=data.numElements
for a = 1:NumDatasetElements
    data{a}.Name=data{a}.Values.data
end

This obviously doesn't work, but I think it shows what I'm trying to do. I need to create a variable with the name data{a}.Name and then set it to data{a}.Values.data.

The reason I'm trying to do this is because I've found that a .mat file populated with array variables easily imports into Python as a dictionary using the sio.loadmat function, whereas datasets do not. My end goal is to easily import Simulink Simulation data into Python to utilize matplotlib for data plotting.

1

1 Answers

0
votes

Inside your loop you want

assignin('base',data{a}.Name,data{a}.Values.data);

However, there are potentially a few problems that you'll need to deal with. Specifically, what if the signal doesn't have a name, and what if the data isn't an array i.e. it may be a timeseries. (The above code will work, but not give you the data you need to easily read into python.) You'll need to add some code to handle both those cases.

There's also the issue of potentially creating lots and lots of variables in your workspace, depending on how much data you are logging.

You may also find that you can just change the format of the saved data to array, in which case none of the above would be required.