How to concatenate multiple structure results vertically?

此生再无相见时 提交于 2019-12-02 14:04:54

问题


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 )


来源:https://stackoverflow.com/questions/17808996/how-to-concatenate-multiple-structure-results-vertically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!