Loading part of a structure in a .mat file

14 次查看(过去 30 天)
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.

采纳的回答

Stephen23
Stephen23 2019-11-27
编辑:Stephen23 2019-11-27
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Structures 的更多信息

标签

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by