MATLAB结构合并 [英] MATLAB structure merge
本文介绍了MATLAB结构合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下结构
data =
id: [143x1 double]
datenum: [143x1 double]
Timestamp: {143x1 cell}
Min_F1_USA_40__u: [143x1 double]
Max_F1_USA_40__u: [143x1 double]
Mean_F1_USA_40__u: [143x1 double]
Stddev_F1_USA_40__u: [143x1 double]
MeanVals_F1_USA_40__u: [143x1 double]
a0_F1_USA_40__u: [143x1 double]
a1_F1_USA_40__u: [143x1 double]
a2_F1_USA_40__u: [143x1 double]
a3_F1_USA_40__u: [143x1 double]
a4_F1_USA_40__u: [143x1 double]
如此,我在结构中有50多个字段
So on, I have more than 50 field in the struct
我还有其他3个结构相同的结构,我想合并此结构
I have other 3 structure with the same structure and I want to merge this struct
当我有3个结构体时,我将得到以下结构体
When I have 3 struct I will get the following structure
data =
id: [429x1 double]
datenum: [429x1 double]
Timestamp: {429x1 cell}
Min_F1_USA_40__u: [429x1 double]
Max_F1_USA_40__u: [429x1 double]
Mean_F1_USA_40__u: [429x1 double]
Stddev_F1_USA_40__u: [429x1 double]
.
.
.
推荐答案
对不起,我误解了您的问题-这是第二次尝试.
Sorry, I had misunderstood your question - here a second try.
也许有一种更简单的方法,但是您可以使用mynames=fieldnames(data)
获取data
中所有字段的列表.然后,您可以遍历它们,并将它们分配给一个通用结构,如下所示:
Maybe there is an easier way, but you can get a list of all fields in data
using mynames=fieldnames(data)
. You can then loop through them all and assign them to a common struct like this:
combineddata.(mynames{i})=[data1.(mynames{i}); data2.(mynames{i}); data3.(mynames{i})];
这篇关于MATLAB结构合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文