Borrar filtros
Borrar filtros

Loading part of a structure in a .mat file

9 visualizaciones (últimos 30 días)
user86753
user86753 el 27 de Nov. de 2019
Editada: Stephen23 el 27 de Nov. de 2019
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.

Respuesta aceptada

Stephen23
Stephen23 el 27 de Nov. de 2019
Editada: Stephen23 el 27 de Nov. de 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

Más respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by