- Variables of tables
- Cells of cell arrays
- Fields of structure arrays
- User-defined classes
- Sparse arrays
Matfile supports only () indexing
14 views (last 30 days)
Show older comments
I have a struct called data(which I created using load command from a -v7.3 matfile) :
>> data =
results: [1x1 struct]
where : >> data.results
ans =
info : [1x1 struct]
signal: [1x80 struct]
i.e, data.results contains two fields info and signal which are also structs. Now since this is a large struct, I use the matfile command to load the original matfile and save this in a new object data2.
data2 =
matlab.io.MatFile
Properties:
Properties.Source: 'C:\Local\...'
Properties.Writable: false
results: [1x1 struct]
data2.results still gives me this result:
K>> data2.results
ans =
info : [1x1 struct]
signal: [1x80 struct]
however, if I try to index further into any of these structs,like data2.results.info I get an error, K>> data2.results.info Cannot index into 'results' because MatFile objects only support '()' indexing.
Anybody having any experience with this ?
0 Comments
Answers (1)
Walter Roberson
on 24 Jan 2016
data2.results(1,1).info would be considered different than what you wrote. But it probably will not work, as the documentation says specifically,
matfile does not support indexing into:
What this tells me is that you would need to use something like,
data2results = data2.results(1,1);
after which you would be able to access data2results.info because the structure would have been completely loaded in.
Only the top level index of a variable can be loaded selectively. It is not possible to selectively load, for example, results(1,1).signal(1,42)
One workaround for this would be to put all of the signal (over possibly multiple struct indices) into a single variable, and keep a smaller struct that indicated the indices into the larger variable. Load the housekeeping struct to find out which indices into the mass storage struct you need and use matfile to bring only those indices into memory.
2 Comments
Walter Roberson
on 24 Jan 2016
matFile() is intended to allow you to load parts of a variable, with the part distinguished entirely by the top level index.
For example instead of storing one struct with subfields 'info' and 'results' into the .mat file, store one variable 'info' and one variable 'results', where results is the 1 x 80 structure array. And then you could load the info variable and use it to figure out what index you need out of results, and then you can
data2.results(1,TheOneIndexYouNeed)
to fetch just that structure.
See Also
Categories
Find more on Workspace Variables and MAT-Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!