Structs fields indexing issue
Afficher commentaires plus anciens
Hi,
I have a structure 'Parent', which stores three structs named 'Child1','Child2' and 'Child3' (these structs have the same fields with different values). I would like to know how to find if any of those 3 structs matches a condition. For example, something like:
find(Parent.*.field_1 == 2)
any help would be appreciated.
Réponse acceptée
Plus de réponses (1)
Jos (10584)
le 7 Mar 2018
Parent.Child1.field_1 = [1 2 2 3] ;
Parent.Child2.field_1 = [1 3 3 2 3 2] ;
Parent.Child3.field_1 = [2] ;
A = structfun(@(S) find(S.field_1==2), Parent, 'un', 0)
A = horzcat(A{:})
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!