Comparing two structures and find the common
31 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Praveen Kumar Pakkirisamy
il 10 Mar 2019
Commentato: madhan ravi
il 10 Mar 2019
I need to compare two strctures and find the common between them and then keep the common fields as the new structure.
4 Commenti
KALYAN ACHARJYA
il 10 Mar 2019
structure_1={'field1','field2','field3'};
structure_2={'field1','field4','field3'};
structure_1=intersect(structure_1,structure_2)
Risposta accettata
Walter Roberson
il 10 Mar 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
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Structures in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!