Comparing two structures and find the common
52 ビュー (過去 30 日間)
古いコメントを表示
Praveen Kumar Pakkirisamy
2019 年 3 月 10 日
コメント済み: madhan ravi
2019 年 3 月 10 日
I need to compare two strctures and find the common between them and then keep the common fields as the new structure.
4 件のコメント
KALYAN ACHARJYA
2019 年 3 月 10 日
structure_1={'field1','field2','field3'};
structure_2={'field1','field4','field3'};
structure_1=intersect(structure_1,structure_2)
採用された回答
Walter Roberson
2019 年 3 月 10 日
common_fields = intersect( fieldnames(structure1), fieldnames(structure2));
for fn = common_fields
this = fn{1};
new_struct(1).(this) = structure1.(this);
new_struct(2).(this) = structure2.(this);
end