MATLAB: Loading part of a structure in a .mat file

loadMATLAB

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.

Best Answer

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