Comparing two structures and find the common
조회 수: 31 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!