"MatFile objects only support '()' indexing" ?

18 views (last 30 days)
Adam
Adam on 27 Sep 2011
Hallo,
I'm using the matfile() to save filtered time series to a particular .MAT file. The reason I'm using matfile() rather than load() is because these data would consume too much memory to load each time I wanted to add some more.
So I have a structure "A" that contains 4 fields which are structures "Aa", "Ab", "Ac", and "Ad".
After having created a matfile object using matfile [matfileObj = matfile(filepath,'Writable',true)], I add the structure "A" to the matfileObj (and so to the .MAT file):
matfileObj.A = A ;
My question:
Is it possible to refer to fields within the substructure in the matfile object?
When I try, e.g., size(matfileObj.A.Aa), the following error is returned:
"Cannot index into 'A' because MatFile objects only support '()' indexing".
It is possible to do size(matfileObj,A).
matfileObj.A(1,1) returns the names the structures "Aa", "Ab", etc.
I cann't figure out how to go deeper. For example, matfileObj.A(1,1,1) does not work, and nor does matfileObj.A(1,1).Aa or matfileObj.A(1,1).Aa(1,1).
Any insight or help would be greatly appreciated.

Answers (2)

Malcolm Lidierth
Malcolm Lidierth on 1 Oct 2011
As Walter points out, the new matfile class has some significant limitations. No linear indexing, no logical indexing, subscripts must increase evenly etc. Hopefully, these restrictions will disappear in later versions. Also, it is really only useful with Version 7.3 MAT-files.
An alternative, with no such restrictions, might be to create a memmapfile object (assuming the time series are stored in a primitive type within your structures). The "where" function in the MAT-file Utilities
provides the required information about disc offsets, formats etc in a Version 6 MAT-file (not 7 or 7.3). Another submission provides an example of how this can be used:
If you can wait, an update to these MAT-file Utilities will be posted in the next week or so. This now includes an updated adcarray class and a general-purpose convenience class, nmatrix, that does the work above for any primitive matrix - including those nested in structures
x=nmatrix(filnename, varname);
% and for structures
x=nmatrix(filename, varname, fieldname)
x=nmatrix(filename, varname, fieldname1, fieldname2 etc...)
The methods of the nmatrix class allow it to be passed to many (perhaps most) existing m-code designed to accept primitive data types on input. It supports the full range of indexing/subreferencing options usually available for those data types.
Support for Version 7.3 MAT-files is currently being added to the nmatrix using matfile objects as the base instead of memmapfiles. These slot in easily enough but may or may not overcome any of the limitations of the matfile class.
The nmatrix class will form part of the next update of Project Waterloo:

Walter Roberson
Walter Roberson on 27 Sep 2011
According to the documentation, size(matfileObj,A) would have to be written size(matfileObj,'A')
matfileObj.A.Aa is implicitly the list matfileObj.A(1).Aa, matfileObj.A(2).Aa matfileObj.A(3).Aa and so on (standard structure index expansion), but the documentation for matfile says specifically that indexing into fields of structure arrays is not supported by matlab.io.matfile objects.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!