[Scipy-tickets] [SciPy] #1319: io.loadmat not working on MATLAB ASCII files

SciPy Trac scipy-tickets@scipy....
Mon Oct 25 11:32:08 CDT 2010

#1319: io.loadmat not working on MATLAB ASCII files
 Reporter:  daviesk24  |       Owner:  somebody
     Type:  defect     |      Status:  new     
 Priority:  normal     |   Milestone:  0.9.0   
Component:  scipy.io   |     Version:  0.7.0   
 Keywords:             |  
 I am just getting started with SciPy.  I'd like to use it to load data
 that a stand-alone program is saving as a MATLAB version 4 in ASCII.  I've
 isolated the problem a little bit.  I'd appreciate any help.  Thanks!

 In MATLAB, try:
 a = 1:10;
 save('test_binary.mat', 'a')
 save('-ascii', 'test_ascii.mat', 'a')

 Then in Python, try:
 import scipy.io

 print "Trying to load test_binary.mat..."
 b = scipy.io.loadmat("test_binary.mat", struct_as_record=True)
 print b

 print "\nTrying to load test_ascii.mat..."
 c = scipy.io.loadmat("test_ascii.mat", struct_as_record=True)
 print c

 I get the following (MATLAB R2007A and Python v2.6 on Ubuntu 10.04):
 Trying to load test_binary.mat...
 {'a': array([[ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10]], dtype=uint8),
 '__version__': '1.0', '__header__': 'MATLAB 5.0 MAT-file, Platform:
 GLNX86, Created on: Mon Oct 25 11:59:50 2010', '__globals__': []}

 Trying to load test_ascii.mat...
 Traceback (most recent call last):
   File "./load_data.py", line 21, in <module>
     c = scipy.io.loadmat("test_ascii.mat", struct_as_record=True)
   File "/usr/lib/python2.6/dist-packages/scipy/io/matlab/mio.py", line
 110, in loadmat
     MR = mat_reader_factory(file_name, appendmat, **kwargs)
   File "/usr/lib/python2.6/dist-packages/scipy/io/matlab/mio.py", line 80,
 in mat_reader_factory
     mjv, mnv = get_matfile_version(byte_stream)
   File "/usr/lib/python2.6/dist-packages/scipy/io/matlab/miobase.py", line
 125, in get_matfile_version
     raise ValueError('Unknown mat file type, version %s' % ret)
 TypeError: not all arguments converted during string formatting

 I've tried all the settings of byte_order in loadmat(), but none seem to

Ticket URL: <http://projects.scipy.org/scipy/ticket/1319>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.

More information about the Scipy-tickets mailing list