Reputation: 547
I am trying to store data in a .mat file using python. The data, an array is updated at each iteration of the for loop. I have trouble achieving this. The code and the error are as attached.
from array import *
import scipy.io
a={}
b=[9,8,7,6]
i=0
for i in range(10):
a['m']=b.append(i)
scipy.io.savemat('test.mat',a)
i+=1
The error I get:
Traceback (most recent call last):
File "C:/Python27/tryin", line 15, in <module>
scipy.io.savemat('test.mat',a)
File "C:\Users\rlangari\Portable Python 2.7.6.1\App\lib\site-packages\scipy\io\matlab\mio.py", line 204, in savemat
MW.put_variables(mdict)
File "C:\Users\rlangari\Portable Python 2.7.6.1\App\lib\site-packages\scipy\io\matlab\mio5.py", line 872, in put_variables
self._matrix_writer.write_top(var, asbytes(name), is_global)
File "C:\Users\rlangari\Portable Python 2.7.6.1\App\lib\site-packages\scipy\io\matlab\mio5.py", line 622, in write_top
self.write(arr)
File "C:\Users\rlangari\Portable Python 2.7.6.1\App\lib\site-packages\scipy\io\matlab\mio5.py", line 643, in write
% (arr, type(arr)))
TypeError: Could not convert None (type <type 'NoneType'>) to array
Upvotes: 0
Views: 2044
Reputation: 679
b.append(i)
returns nothing. therefore each time you're getting an exception.
Upvotes: 1