1

I have few lists which i want to save it to a *.mat file. But according to scipy.io.savemat command documentation i Need to create a dictionary with the lists and then use the command to save it to a *.mat file.

If i save it according to the way mentioned in the docs the mat file will have structure with variables as the Arrays which i used in the dictionary. Now i have a Problem here, I have another program (which is not editable) will use the mat files and load them to plot some Graphs from the data. The program cannot process the structure because it is written in a way where if it loads a mat files and then it will directly process the Arrays in it.

So is there a way to save the mat file without using dictionaries? Please see the Image for more understanding*.mat file with struct

*.mat file without struct

Thanks

This is the sample algorithm i used to save my *.mat file

import os
os.getcwd()
os.chdir(os.getcwd())
import scipy.io as sio

x=[1,2,3,4,5]
y=[234,5445,778] #can be 1000 lists

data={}

data['x']=x
data['y']=y
sio.savemat('test.mat',{'interpolated_data':data})
5
  • Don't you simply need a dictionary where keys (which will be names after loaded in MATLAB) corresponds with names expected in this non-editable program? Commented Jun 14, 2017 at 11:14
  • @ŁukaszRogalski I did not understand what you mean exactly. Can you explain it a bit more Commented Jun 14, 2017 at 11:21
  • can you add an example of the code that calls scipy.io.savemat? it seems like you are abusing this function... Commented Jun 14, 2017 at 11:35
  • 1
    @Shai I will add the code Commented Jun 14, 2017 at 11:36
  • @Shai I added the code Commented Jun 14, 2017 at 11:50

2 Answers 2

2

How about

scipy.io.savemat('interpolated_data_max_compare.mat', 
                 {'NA1_X_order10_ACCE_ms2': np.zeros((3000,1)),
                  'NA1_X_order10_DISP_mm': np.ones((3000,1))})

Should work fine...

According to the code you added in your question, instead of sio.savemat('...', {'interpolated_data':data}), just save

sio.savemat('...', data)

and you should be fine: data is already a dictionary you don't need to add an extra level with {'interpolated_data': data} when saving.

Sign up to request clarification or add additional context in comments.

1 Comment

If i have many lists how you would you suggest me to write the command?
1

You could use the Writing primitives directly

import scipy.io.matlab as ml

f=open("something.mat","wb")
mw=ml.mio5.MatFile5Writer(f)
mw.put_variables({"testVar":22})

3 Comments

shouldn't f be open for write (and binary?). what is s? should it be f?
can you add a link do a documentation of ml.mio5? is it possible it's simply the backend of scipy.io.savemat?
Yes and yes, it's the backend, scipy.io.matlab.mio5 referenced at the end of savemat help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.