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

Benjamin Root ben.root@ou....
Tue Oct 5 09:13:19 CDT 2010


On Tue, Oct 5, 2010 at 8:55 AM, Dharhas Pothina <
Dharhas.Pothina@twdb.state.tx.us> wrote:

>
> @ Mathew
> > I suspect it must be being written from outside matlab.
>
> You are right, this file is being written by a instrument software (Sontek
> River Surveyor Live). Unfortunately, the new version of this instrument and
> software no longer allows export of data in any format but .mat.
>
> > Is there any way you can load these into matlab and fix them up before
> > loading into scipy?
>
> 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.
>
> > Matlab can handle that, although I don't know how you can make a
> > structure that has two fields with the same name - as far as I know
> > there's no way to do that with matlab syntax, e.g:
>
> I opened the files in matlab (v R14) and I can see the 4 duplicate StationQ
> arrays but I don't seem to be able access them separately. The Array Editor
> view and the tab complete shows the 4 Station_Q but I can only access a
> Summary.StationQ and I don't know which one of the 4 it is accessing. The
> documentation for software that describes the matlab variables/structures
> generated by the matlab export command does not list Summary.StationQ at
> all. It isn't one of the primary variables we need and I'm not sure what it
> contains. I am assuming the four copies is a bug in their software, I'm
> going to call them and submit a bug report, not sure how much traction it
> will get though. The other option is that it represents data from the 4
> sonar beams but in all the other structures that have data from the 4 beams
> the data is represented by a 2D array.
>
> @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. My vote would be for skipping the duplicates and
> issuing a warning. That would allow for a more robust way loading the file
> into scipy directly and also avoid matlab completely.
>
> Thanks for all your help on this.
>
> - dharhas
>
>
>
I did a little bit of testing on this issue since I was curious about how
this is even possible.

It appears that the Station_Q that you are accessing is the last one.  If I
modify the contents of x.Summary.Station_Q, and then display what is in
x.Summary, the last Station_Q is changed.  It is *possible* to get access to
the other 3 Station_Q variables if you use the "struct2cell" function, which
gets you back everything in a cell array

I wonder if Matlab is loading the data into a cell array first and then --
somehow --- converting that into a structure.

BTW, this was checked using Matlab R2008b.

Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20101005/84e35a8c/attachment.html 


More information about the SciPy-User mailing list