MATLAB: How to access data in a nested structures

MATLABnested structure

Hi,
how do I access parts of the following structure:
a(1).b.c = 1;
a(2).b.c = 2;
I want a vector containing the c's.
This seems to work:
vec = cat(1,cat(1,a(:).b).c);
Is this the correct way?
Why does this not work:
[a(:).b].c
Thanks!

Best Answer

"Is this the correct way?"
The usual MATLAB way is to use two lines, e.g.:
tmp = [a.b];
out = [tmp.c];
"Why does this not work: [a(:).b].c"
Because MATLAB does not allow indexing directly into the output of expressions (and accessing the field of a structure is a kind of indexing)