MATLAB: Vertical concatenation of structure fields (compact form)

concatenationfieldsMATLABstructures

Hi,
I know there is a similar question but it's not about the compact form.
My question is: why does the following not result in a vertical concatenation? (it also fails for numerical values)
Or, how can I change it to concatenate vertically into ['value_1' ; 'value_2'] ?
Thanks!
>> structure(1, 1).field = 'value_1';
>> structure(2, 1).field = 'value_2';
>> [structure(:, 1).field]
ans =
'value_1value_2'
>>

Best Answer

Your example concatenates horizontally because it is exactly equivalent to doing this:
[structure(1).field,structure(2).field]
which is just shorthand for
horzcat(structure(1).field,structure(2).field)
If you want to concatenate vertically, use either of these
vertcat(structure.field)
cat(1,structure.field)
For more information on how to use comma-separated lists: