[SciPy-User] Using scipy.io.loadmat to read Matlab containers.Map object?

Matthew Brett matthew.brett at gmail.com
Tue May 15 04:37:58 EDT 2012


On Tue, May 15, 2012 at 1:17 AM, Gerrit Holl <gerrit.holl at ltu.se> wrote:
> On 14 May 2012 20:36, Matthew Brett <matthew.brett at gmail.com> wrote:
>> Hi,
>> On Mon, May 14, 2012 at 7:51 AM, Gerrit Holl <gerrit.holl at ltu.se> wrote:
>>> Hi,
>>> is it possible to use scipy.io.loadmat to read a Matlab containers.Map object?
>>>>> cm = containers.Map();
>>>>> cm('abc') = 42;
>>>>> save('/tmp/test.mat', 'cm');
>>> In [15]: M = scipy.io.loadmat('/tmp/test.mat')
>>> In [16]: M.keys()
>>> Out[16]: ['__function_workspace__', 'None', '__version__',
>>> '__header__', '__globals__']
>>> In [17]: M["None"]
>>> Out[17]:
>>> MatlabOpaque([ ('cm', 'MCOS', 'containers.Map', [[3707764736L], [2L],
>>> [1L], [1L], [1L], [1L]])],
>>>      dtype=[('s0', '|O8'), ('s1', '|O8'), ('s2', '|O8'), ('arr', '|O8')])
>> Just because I didn't know what a container.Map was, it looks like
>> it's a MATLAB dict equivalent:
>> http://www.mathworks.com/help/techdoc/matlab_prog/brqqo69.html
>> I see that I or someone thought that types labeled as MatlabOpaque
>> were MATLAB functions:
>> https://github.com/scipy/scipy/blob/master/scipy/io/matlab/mio5_params.py#L51
>> but at least, the internal structure looks rather confusing.  Do you
>> recognize any of the structure in what got loaded?  Does it load OK
>> when loaded in Octave?
> I don't recognise anything, and nor does Octave.
> containers.Map are a relatively new type in Matlab, not very well
> known and quite underused. They're indeed very close to being a Python
> dict, except that all keys must be of the same type and can only be
> numeric or character arrays. But that means that Matlab->Python is a
> well-defined translation.
> It appears the answer to my question is "no". Is this something to
> file an 'issue' for, I suppose it would be desirable to be able to
> read those?

Yes, er, the answer is 'no', sorry about that.  But, please do file an
issue for it.  It would be good to be able to read them, but I guess
it will be hard work getting there.  Do you know of any documentation
for the binary (.mat file) format of these things?  You might get an
idea of where we are by scanning the comments at the top of



More information about the SciPy-User mailing list