Structs fields indexing issue
古いコメントを表示
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.
採用された回答
その他の回答 (1 件)
Jos (10584)
2018 年 3 月 7 日
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{:})
カテゴリ
ヘルプ センター および File Exchange で Structures についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!