MATLAB: Structs fields indexing issue

indexindexingstructstructuresvariablevariables

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.

Best Answer

If all of the child structures have exactly the same fields then you would be much better off using a non-scalar structure instead of nested structures:
S(1).field = ...
S(2).field = ...
S(3).field = ...
Then you could trivially do this:
find([S.field] == 2)
Using a non-scalar structure would make your code much simpler and more efficient.