Filter löschen
Filter löschen

Comparing two structures and find the common

84 Ansichten (letzte 30 Tage)
Praveen Kumar Pakkirisamy
Praveen Kumar Pakkirisamy am 10 Mär. 2019
Kommentiert: madhan ravi am 10 Mär. 2019
I need to compare two strctures and find the common between them and then keep the common fields as the new structure.
  4 Kommentare
KALYAN ACHARJYA
KALYAN ACHARJYA am 10 Mär. 2019
structure_1={'field1','field2','field3'};
structure_2={'field1','field4','field3'};
structure_1=intersect(structure_1,structure_2)
madhan ravi
madhan ravi am 10 Mär. 2019
Sir Walter has given the answer already before 24mins..

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 10 Mär. 2019
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

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by