[Mne_analysis] np arrays to Matlab?

Mads Jensen mje.mads at gmail.com
Wed Oct 22 02:59:11 EDT 2014
Search archives:

Hi Maria,

The data has to be a dict to use "savemat", e.g.
     import numpy as np
     import scipy.io

     x = np.linspace(0, 2 * np.pi, 100)
     y = np.cos(x)

     scipy.io.savemat('test.mat', dict(x=x, y=y))

example is taken from 
http://stackoverflow.com/questions/10997254/converting-numpy-arrays-to-matlab-and-vice-versa

but also see 
http://docs.scipy.org/doc/scipy-0.14.0/reference/tutorial/io.html

best,
mads

On 22/10/14 08:52, Maria Hakonen wrote:
> Hi all,
>
> I wonder if it is possible to pass the np arrays in Matlab?
>
> I tried:
> scipy.io.savemat('test.mat',data)
>
> where data is np array but got:
>
> ----> 1 scipy.io.savemat('test.mat',data)
>
> /usr/lib/python2.7/dist-packages/scipy/io/matlab/mio.pyc in
> savemat(file_name, mdict, appendmat, format, long_field_names,
> do_compression, oned_as)
>      233     else:
>      234         raise ValueError("Format should be '4' or '5'")
> --> 235     MW.put_variables(mdict)
>      236     if file_is_string:
>      237         file_stream.close()
>
> /usr/lib/python2.7/dist-packages/scipy/io/matlab/mio5.pyc in
> put_variables(self, mdict, write_header)
>      823             self.write_file_header()
>      824         self._matrix_writer = VarWriter5(self)
> --> 825         for name, var in mdict.items():
>      826             if name[0] == '_':
>      827                 continue
>
> AttributeError: 'numpy.ndarray' object has no attribute 'items'
>
>
>
> Thanks,
> Maria
>
>
> _______________________________________________
> Mne_analysis mailing list
> Mne_analysis at nmr.mgh.harvard.edu
> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>
>
> The information in this e-mail is intended only for the person to whom it is
> addressed. If you believe this e-mail was sent to you in error and the e-mail
> contains patient information, please contact the Partners Compliance HelpLine at
> http://www.partners.org/complianceline . If the e-mail was sent to you in error
> but does not contain patient information, please contact the sender and properly
> dispose of the e-mail.
>



More information about the Mne_analysis mailing list