编者按:这个文件被选为MATLAB中央选择的
CATSTRUCT连接或合并结构与不同的字段名
X = CATSTRUCT (S1, S2、S3…)合并结构S1、S2、S3……成一个新的结构出现在各种X X包含所有字段
结构。一个例子:
A.name =“我”;
B。在come = 99999 ;
X = catstruct (A, B)
% - > X.name =“我”;
% X。在come = 99999 ;
如果一个字段名没有独特的结构(即。,a fieldname is present in more than one structure), only the value from the last structure with this field is used. In this case, the fields are alphabetically sorted. A warning is issued as well. An axample:
S1.name =“我”;
S2。= 20岁;S3。= 30岁;S4。年龄= 40;
S5。诚实= false;
Y = catstruct (S1, S2、S3、S4 S5)从S4 %使用价值
输入数组的结构。所有结构都应该有相同的大小。一个例子:
C (1)。空气= 1;C (2)。bb = 2;
D (1)。aa = 3;D (2)。aa = 4;
CD = catstruct (C, D) % CD是一个1 x2结构数组字段bb和aa
最后输入字符串“排序”。在这种情况下,
CATSTRUCT (S1, S2,…,'sorted') will sort the fieldnames alphabetically. To sort the fieldnames of a structure A, you could use CATSTRUCT(A,'sorted') but I recommend ORDERFIELDS for doing that.
没有连接时,结果将是一个空的结构(0 x0结构体数组没有字段)。
请注意
将类似的结构体数组,您可以使用简单的连接:
一个= dir (* .mat);B = dir (“* m”);C =[一个;B];
最新版本:4.0(2013年12月)
引用作为
乔斯(10584)(2023)。CATSTRUCT(//www.tatmou.com/matlabcentral/fileexchange/7842-catstruct), MATLAB中央文件交换。检索。