Vertical concatenation of structure fields (compact form)
Show older comments
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'
>>
Accepted Answer
More Answers (2)
Bjorn Gustavsson
on 8 Oct 2020
This gets you to a 2-by-suitable char array:
char(structure.field)
But this will obviously not be a general solution for fields of different data-types.
HTH
Ameer Hamza
on 8 Oct 2020
By default [] is equivalent to horizontal concatination hozcat(). Use vertcat() for vertical output
vertcat(structure.field)
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!