0

I am trying to append data to an existing .mat file in python. See the following code:

with open('train_x.mat','ab') as f:
         scipy.io.savemat(f, {'data':image_data})

After appending is done when I am trying to load the file as:

training_x = scipy.io.loadmat('train_x')

It is showing the following error:

/usr/lib/python2.7/dist-packages/scipy/io/matlab/mio.py:135: MatReadWarning:
Duplicate variable name "data" in stream - replacing previous with new
Consider mio5.varmats_from_mat to split file into single variable files
matfile_dict = MR.get_variables(variable_names)
Traceback (most recent call last):
File "test2.py", line 3, in <module>
training_x = scipy.io.loadmat('train_x')
File "/usr/lib/python2.7/dist-packages/scipy/io/matlab/mio.py", line 135, in loadmat
matfile_dict = MR.get_variables(variable_names)
File "/usr/lib/python2.7/dist-packages/scipy/io/matlab/mio5.py", line 272, in get_variables
hdr, next_position = self.read_var_header()
File "/usr/lib/python2.7/dist-packages/scipy/io/matlab/mio5.py", line 231, in read_var_header
raise TypeError('Expecting miMATRIX type here, got %d' % mdtype)
TypeError: Expecting miMATRIX type here, got 2375258764

The file is around 30MB. When I tried to open it in Matlab, it is showing following error:

Error using load
Unable to read MAT-file /home/sonu/Desktop/Code/train_x.mat. File might be corrupt.

I am not getting why is it happening, please help.

Sonu Patidar
  • 701
  • 1
  • 5
  • 10

0 Answers0