[SciPy-user] reading .mat-files (Matlab 7)

Nils Wagner nwagner@iam.uni-stuttgart...
Wed Jul 25 14:30:55 CDT 2007


On Wed, 25 Jul 2007 21:25:36 +0200
  oliver.tomic@matforsk.no wrote:
> 
> Rob and Stefan,
> 
> the problem below described by Rob is exactly what I 
>have experienced. I
> get the same error. I use scipy 0.5.2 and numpy 1.0.3.
> 
> Is there a newer version of scipy than 0.5.2 or do I 
>have to use the svn?
> 
> Here is a file that failed to load with scipy.io:
> (See attached file: brod.mat)
> It was created with Matlab 7.3 with backward 
>compatibility to (-v6).
> 
> Cheers
> Oliver
> 
> 
> 
> scipy-user-bounces@scipy.org wrote on 25.07.2007 
>17:05:28:
> 
>> Stefan,
>>
>> scipy.io.loadmat from scipy 0.5.2 doesn't work on 
>>anything but v4
>> files for me. I generated extremely simple mat files 
>>(one small matrix
>> in 'test.mat') with my matlab 7.3 using the -v6, -v5, 
>>and -v4 options,
>> and scipy complained with this in all but the -v4 case:
>>
>> In [1]: import scipy.io as io
>>
>> In [2]: io.loadmat('test')
>>
> ---------------------------------------------------------------------------
>> exceptions.AttributeError 
>>                           Traceback (most
>> recent call last)
>>
>> c:\temp\<ipython console>
>>
>> C:\Python24\lib\site-packages\scipy\io\mio.py in 
>>loadmat(file_name,
>> mdict, appen
>> dmat, basename, **kwargs)
>>      94     '''
>>      95     MR = mat_reader_factory(file_name, 
>>appendmat, **kwargs)
>> ---> 96     matfile_dict = MR.get_variables()
>>      97     if mdict is not None:
>>      98         mdict.update(matfile_dict)
>>
>> C:\Python24\lib\site-packages\scipy\io\miobase.py in
>> get_variables(self, variable_names)
>>     267             variable_names = [variable_names]
>>     268         self.mat_stream.seek(0)
>> --> 269         mdict = self.file_header()
>>     270         mdict['__globals__'] = []
>>     271         while not self.end_of_stream():
>>
>> C:\Python24\lib\site-packages\scipy\io\mio5.py in 
>>file_header(self)
>>     508         hdict = {}
>>     509         hdr = 
>>self.read_dtype(self.dtypes['file_header'])
>> --> 510         hdict['__header__'] = 
>>hdr['description'].strip('
> \t\n\000')
>>     511         v_major = hdr['version'] >> 8
>>     512         v_minor = hdr['version'] & 0xFF
>>
>> AttributeError: 'numpy.ndarray' object has no attribute 
>>'strip'
>>
>>
>> This is with numpy 1.0.2. I wonder if this is the 
>>problem that Oliver
> has?
>>
>> -Rob
>>
>> On 25/07/07, Stefan van der Walt <stefan@sun.ac.za> 
>>wrote:
>> > Hi Oliver
>> >
>> > On Wed, Jul 25, 2007 at 01:06:18PM +0200, 
>>oliver.tomic@matforsk.no
> wrote:
>> > > Is there now support in scipy.io (scipy 0.52) for 
>>reading .mat-files
> from
>> > > Matlab 7? I undestand that it supports older 
>>versions (v4 and v5).
> Are
>> > > there any plans to support for Matlab 7 .mat-files?
>> >
>> > >From the docstring:
>> >
>> > "v4 (Level 1.0), v6 and v7.1 matfiles are supported."
>> >
>> > Cheers
>> > Stéfan
>> > _______________________________________________
>> > SciPy-user mailing list
>> > SciPy-user@scipy.org
>> > http://projects.scipy.org/mailman/listinfo/scipy-user
>> >
>> _______________________________________________
>> SciPy-user mailing list
>> SciPy-user@scipy.org
>> http://projects.scipy.org/mailman/listinfo/scipy-user

No problem with the svn version. It's time for a new
release ...

>>> from scipy import *
>>> io.loadmat('brod.mat')
{'Brod': array([[  1. ,   1. ,   1. , ...,   1. ,   5.6, 
  4.7],
        [  1. ,   1. ,   2. , ...,   1. ,   5.1,   4.1],
        [  1. ,   2. ,   1. , ...,   4.4,   4.8,   3.7],
        ...,
        [ 12. ,   6. ,   2. , ...,   1.8,   2.8,   4.2],
        [ 12. ,   7. ,   1. , ...,   2. ,   4.9,   4.4],
        [ 12. ,   7. ,   2. , ...,   1.3,   5.2,   3.9]]), 
'__version__': '1.0', '__header__': 'MATLAB 5.0 MAT-file, 
Platform: PCWIN, Created on: Wed Jul 25 21:21:07 2007', 
'__globals__': []}
  
Nils


More information about the SciPy-user mailing list