Matfile supports only () indexing

13 visualizzazioni (ultimi 30 giorni)
Moiz
Moiz il 24 Gen 2016
Commentato: Walter Roberson il 24 Gen 2016
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 ?

Risposte (1)

Walter Roberson
Walter Roberson il 24 Gen 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:
  • Variables of tables
  • Cells of cell arrays
  • Fields of structure arrays
  • User-defined classes
  • Sparse arrays
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 Commenti
Moiz
Moiz il 24 Gen 2016
Thanks Walter. This answer helps however I am still trying to understand the second part.
So firstly, indeed this works data2results = data2.results(1,1); However wouldn't this defeat the purpose of using matfile because the whole results struct would get loaded in and this would end up taking the same time as 'load' .
And now for the second bit.. "One workaround for this would be to put all of the signal.."
To put all of signal into one variable I would have to load the full struct data2.results in the first place right ? i.e, I'd need to: data2results = data2.results(1,1); newSingleVariable = data2results.signal; Again the first line would be the time consuming part. I am not sure if I understand you fully here..
Walter Roberson
Walter Roberson il 24 Gen 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.

Accedi per commentare.

Categorie

Scopri di più su Function Creation in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by