Azzera filtri
Azzera filtri

Loading part of a structure in a .mat file

9 visualizzazioni (ultimi 30 giorni)
Is there a way to load part of a cell array that has been saved to a .mat file?
I have a cell array as outlined below and saved to disk as 'test.mat'
test{1}
test{2}
test{3}
Can I load only test{1} from the saved .mat file?
I have tried the code below but I get the following error
a = matfile('test.mat');
dat = a.test{1};
Cannot index into 'test' because MatFile objects only support '()' indexing.

Risposta accettata

Stephen23
Stephen23 il 27 Nov 2019
Modificato: Stephen23 il 27 Nov 2019
The matfile documentation states "The MAT-file object does not support indexing into... Cells of cell arrays..."
This means you can use parenthesis indexing to return the cells themselves, but not curly-brace indexing to access the contents of the cells:
"Is there a way to load part of a cell array that has been saved to a .mat file?"
Of course, you can use parentheses (which will return a cell array, from which you can trivially access its contents):
>> C = {'hello','world',NaN};
>> save('test.mat','C','-v7.3');
>> clear
>> M = matfile('test.mat');
>> D = M.C(1,2) % D is a cell array containing a character vector
D =
'world'
>> S = D{1} % S is a character vector
S =
world

Più risposte (0)

Categorie

Scopri di più su Structures in Help Center e File Exchange

Tag

Prodotti


Release

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by