1

I need to extract few signals from mf4 file and save them in .mat file. The signals look like this:

camera_detection.timestamp.seconds.value   
camera_detection.timestamp.nanoseconds.value 
camera_detection.object._0_.type                  
camera_detection.object._0_.position_x          
camera_detection.object._0_.position_y           
camera_detection.object._1_.type                 
camera_detection.object._1_.position_x           
camera_detection.object._1_.position_y
       

So, when the above signals are saved in .mat file they should look like nested structs as below:

struct camera_detection with fields:

timestamp [1x1 struct with fields seconds and nanoseconds]
object [2x1 struct of array with fields type, position_x, position_y]

I am using asammdf library to read mf4 file and scipy.io to save python dict object to save to mat file. So far, I am able to save basic types like first 2 signals from example above as follows:

### output dictionary
output = {}  

### Read file 
mdf = MDF("file.mf4")

for sig in mdf.iter_channels():
    parts = sig.name.split(".")
    current = output.setdefault(parts[0], {})

    for i in range(1,len(parts) - 1):
        current = current.setdefault(parts[i],{})
    
    current[parts[-1]] = sig.samples

### Save to mat file
savemat("out.mat", output)

However, I am not able to build this dynamic dictionary for signal containing array. Can anyone suggest something?

I want to build the dictionary dynamically meaning I do not know signal structure and array size beforehand. Also there can be n levels of array.

Anonymous
  • 336
  • 3
  • 23

0 Answers0