Structs fields indexing issue
Mostrar comentarios más antiguos
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.
Respuesta aceptada
Más respuestas (1)
Jos (10584)
el 7 de Mzo. de 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{:})
Categorías
Más información sobre Structures en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!