<h1 dir="auto">----------------------------------------------------</h1>
<h1 dir="auto">This works</h1>
<h1 dir="auto">----------------------------------------------------</h1>
<p dir="auto">import scipy.io as sio<br>
a_dict = {'field1': 0.5, 'field2': 'a string'}<br>
sio.savemat('saved_struct.mat', {'a_dict': a_dict})</p>
<h1 dir="auto">----------------------------------------------------</h1>
<p dir="auto">from pydal import DAL, Field<br>
db = DAL('sqlite://storage.db')<br>
db.define_table('thing',Field('name'))<br>
db.thing.insert(name='Chair')<br>
db.commit()<br>
a = db().db.thing.as_dict();</p>
<h1 dir="auto">a is a dict, you can print out</h1>
<h1 dir="auto">Now if you do</h1>
<p dir="auto">sio.savemat('saved_struct.mat', {'a': a})</p>
<h1 dir="auto">gives you a type error because</h1>
<p dir="auto">Could not convert None (type &lt;type 'NoneType'&gt;) to array</p>
<p dir="auto">The MATLAB equivalent of None is the empty array []. It looks like scipy does not perform this conversion.</p>
<p dir="auto">But if I try to save a dict with a None inside it, I get this: (scipy 0.13.0 in Anaconda Python on Windows 7 64-bit)</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;&gt;&gt; import scipy.io
&gt;&gt;&gt; scipy.io.savemat('test.mat',{'x':3})
&gt;&gt;&gt; scipy.io.savemat('test.mat',{'x':None})
Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;c:\app\python\anaconda\1.6.0\envs\daqlogger\lib\site-packages\scipy\io\m
atlab\mio.py&quot;, line 204, in savemat
    MW.put_variables(mdict)
  File &quot;c:\app\python\anaconda\1.6.0\envs\daqlogger\lib\site-packages\scipy\io\m
atlab\mio5.py&quot;, line 872, in put_variables
    self._matrix_writer.write_top(var, asbytes(name), is_global)
  File &quot;c:\app\python\anaconda\1.6.0\envs\daqlogger\lib\site-packages\scipy\io\m
atlab\mio5.py&quot;, line 622, in write_top
    self.write(arr)
  File &quot;c:\app\python\anaconda\1.6.0\envs\daqlogger\lib\site-packages\scipy\io\m
atlab\mio5.py&quot;, line 643, in write
    % (arr, type(arr)))
TypeError: Could not convert None (type &lt;type 'NoneType'&gt;) to array"><pre class="notranslate"><code class="notranslate">&gt;&gt;&gt; import scipy.io
&gt;&gt;&gt; scipy.io.savemat('test.mat',{'x':3})
&gt;&gt;&gt; scipy.io.savemat('test.mat',{'x':None})
Traceback (most recent call last):
  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  File "c:\app\python\anaconda\1.6.0\envs\daqlogger\lib\site-packages\scipy\io\m
atlab\mio.py", line 204, in savemat
    MW.put_variables(mdict)
  File "c:\app\python\anaconda\1.6.0\envs\daqlogger\lib\site-packages\scipy\io\m
atlab\mio5.py", line 872, in put_variables
    self._matrix_writer.write_top(var, asbytes(name), is_global)
  File "c:\app\python\anaconda\1.6.0\envs\daqlogger\lib\site-packages\scipy\io\m
atlab\mio5.py", line 622, in write_top
    self.write(arr)
  File "c:\app\python\anaconda\1.6.0\envs\daqlogger\lib\site-packages\scipy\io\m
atlab\mio5.py", line 643, in write
    % (arr, type(arr)))
TypeError: Could not convert None (type &lt;type 'NoneType'&gt;) to array
</code></pre></div>