[SciPy-user] Re: io.loadmat

Nils Wagner nwagner at mecha.uni-stuttgart.de
Wed Oct 15 05:20:03 EDT 2003


Andrew Straw schrieb:
> 
> John Hunter wrote:
> >>>>>>"Nils" == Nils Wagner <wagner.nils at vdi.de> writes:
> >
> >
> >     Nils> Thank you for your note. However, I am not the right person
> >     Nils> for doing that. It would be great if someone else can do
> >     Nils> that.  Thanks in advance.
> >
> >
> > Have you seen matfile?  It will load matlab version 5 into Numeric
> > arrays
> >
> > See
> > http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&safe=off&threadm=m3g09ck23n.fsf%40nmw-office.ion.le.ac.uk&rnum=2&prev=/groups%3Fnum%3D20%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26safe%3Doff%26q%3Dmatfile%2Bpython%26sa%3DN%26tab%3Dwg
> >
> > and the src at ftp://ion.le.ac.uk/matfile/matfile.tar.gz
> 
> Cool!  I hadn't seen that before, and it seems to work on the simple
> test case I tried.  I made a setup script rather than fiddling with the
> Makefile.  This seems like a useful enough utility that it should get
> wider exposure.  Too bad it can't be incorporated into scipy as is (GPL
> vs. BSD license issues...).
> 
> #!/usr/bin/env python
> """Setup script for matfile
> """
> 
> from distutils.core import setup, Extension
> import distutils.sysconfig
> import os
> 
> numpy_inc_dir = os.path.join(distutils.sysconfig.get_python_inc(),'Numeric')
> matfile_dir = 'matfile' # off current directory
> 
> matfile_srcs = ['mat_open.c', 'mat_read_array.c', 'mat_copy_data.c',
>          'mat_free_array.c', 'mat_read_array4.c', 'mat_write_array4.c',
>          'mat_read_array5.c', 'mat_subarray5.c', 'mat_utils5.c']
> matfile_srcs = [ os.path.join(matfile_dir,src) for src in matfile_srcs ]
> 
> setup(name="matfile",
>        description = "MATLAB .mat file reader for Python",
>        author = "Nigel Wade",
>        author_email = "nmw at ion.le.ac.uk",
>        license = "GNU GPL",
>        ext_modules = [Extension(name='matfile',
>                                 sources=['matfilemodule.c']+matfile_srcs,
>                                 include_dirs=[matfile_dir,
>                                               numpy_inc_dir])])
> 
Andrew,

I have used your setup script. 
However, I get into trouble

from scipy import *
import matfile
load("matrizen_red.mat")
#io.loadmat("matrizen_red.mat",appendmat=0)


Traceback (most recent call last):
  File "matlab.py", line 3, in ?
    load("matrizen_red.mat")
  File "/usr/local/lib/python2.1/site-packages/Numeric/Numeric.py", line
506, in load
    return Unpickler(file).load()
  File "/usr/local/lib/python2.1/pickle.py", line 554, in __init__
    self.readline = file.readline
AttributeError: readline

Any suggestion ?

                   Nils


>   ------------------------------------------------------------------------
>    Part 1.1.2Type: application/pgp-signature
> 
>    Part 1.2    Type: Plain Text (text/plain)
>            Encoding: 7bit



More information about the SciPy-User mailing list