[SciPy-User] scipy.io.loadmat error when trying to read a .mat file

Matthew Brett matthew.brett@gmail....
Tue Oct 5 13:01:48 CDT 2010


Hi,

> I'm trying to get rid of the matlab dependency since we only have one copy available and I'm trying to write some automated processing scripts.

That's easy to imagine...

> @Pauli & Mathew
>> Renaming to "originalname_counter" sounds like an OK solution. Skipping
>> duplicates + emitting a warning might also be OK...
>
> Since it looks like matlab cannot handle duplicate field names (at least w/ R14 I haven't tried more recent versions) in terms of accessing the variable once loaded in, and also since it is impossible to make a structure with duplicate field names within matlab, I think this is an error in the way the data file is being written.

Yes, I'm sure it's an error, but I suppose we should set ourselves the
goal of being able to read what matlab can read.

I don't like the 'originalname_counter' option because that might
conceivably still clash with the intended fieldnames (imagine the
original fieldnames of ['field1_1', 'field1', 'field1'] for example).
 I see that matlab intends names prepended with an underscore to be
invalid:

>> a = [];
>> a._field1 = 1
??? a._field1 = 1
      |
Error: The input character is not valid in MATLAB statements or expressions.

So one option would be ['field1_1', 'field1', 'field1'] ->
['field1_1', 'field1', '_0_field1'] .   It would be a problem when
saving back to matlab, but that seems like a sensible problem to have.

Best,

Matthew


More information about the SciPy-User mailing list