如何垂直连接多个结构的结果吗? [英] How to concatenate multiple structure results vertically?

查看:101
本文介绍了如何垂直连接多个结构的结果吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有结构数组和矩阵索引访问它,我得到多个ANSES。

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?

如何让垂直串联?

推荐答案

使用 vertcat

vertcat( a(:).f1 )

这篇关于如何垂直连接多个结构的结果吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆