使用python使用for循环将数据保存在.mat文件中

时间:2014-07-29 17:38:58

标签: python scipy

我正在尝试使用python将数据存储在.mat文件中。数据,数组在for循环的每次迭代中更新。我无法实现这一目标。代码和错误都是附加的。

    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

我得到的错误:

    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

1 个答案:

答案 0 :(得分:1)

b.append(i) 

什么都不返回。因此,每次你获得例外。