How to concatenate multiple structure results vert

2020-04-20 09:29发布

问题:

If I have structure array and access it with matrix index, I get multiple anses.

>> a=struct([])

a = 

0x0 struct array with no fields.

>> a(1).f1=[1;2]

a = 

    f1: [2x1 double]

>> a(2).f1=[1;2;3]

a = 

1x2 struct array with fields:

    f1

>> a([1 2]).f1

ans =

     1
     2


ans =

     1
     2
     3

What is the nature of this result? Can I generate it in other way?

For example, may I write my own function or procedure, which will return such a result?

Why assignment of this result gives first element, not last like in lists?

>> b=a([1 2]).f1

b =

     1
     2

If I enclose such a result in brackets, I get automatic horizontal concatenation.

>> [a([1 2]).f1]
Error using horzcat
Dimensions of matrices being concatenated are not consistent.

What is the name of this syntax?

How to make vertical concatenation?

回答1:

use vertcat

vertcat( a(:).f1 )