checking if field values in a single struct are identical
Afficher commentaires plus anciens
Hello,
I have a struct (S) with 13 fields. Each field has a 'density' column. I want to do an if statement which checks if all the values in the density columns are the same for each field (all 13 of them) i.e. density vals in field 1 = density vals in field 2 etc
if...(need help with this line)
disp('same altitude')
else
disp('different heights')
end
thank you
1 commentaire
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 19 Jan 2023
density_cell = structfun(@(C) {C.density}, YourStruct);
EQ = isequal(density_cell{:});
No explicit loop needed (but structfun is arguably a hidden loop.)
Catégories
En savoir plus sur Structures dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!