【问题标题】:How to concatenate multiple structure results vertically?如何垂直连接多个结构结果?
【发布时间】:2013-07-23 11:31:54
【问题描述】:

如果我有结构数组并使用矩阵索引访问它,我会得到多个答案。

>> 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

这个结果的性质是什么?我可以用其他方式生成它吗?

例如,我可以编写自己的函数或过程,它会返回这样的结果吗?

为什么这个结果的赋值给出了第一个元素,而不是列表中的最后一个?

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

b =

     1
     2

如果我将这样的结果括在括号中,我会得到自动水平连接。

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

这个语法叫什么名字?

如何进行垂直拼接?

【问题讨论】:

    标签: arrays matlab structure concatenation


    【解决方案1】:

    使用vertcat

    vertcat( a(:).f1 )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多