- Variables of tables
- Cells of cell arrays
- Fields of structure arrays
- User-defined classes
- Sparse arrays
Matfile supports only () indexing
13 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Walter Roberson
2016-1-24
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 个评论
Walter Roberson
2016-1-24
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!