2

I have an array of nested structure. for example

st(1).a.b.c=1
st(2).a.b.c=2
st(3).a.b.c=3

...and so on

If I wanted to find the index number of the '.c' objects containing the number 3, I try the following function

find([st.a.b.c]==3)

It gives this error:

Expected one output from a curly brace or dot indexing expression, but there were 3 results.

Could anybody help me to solve this problem?

Arya McCarthy
  • 8,554
  • 4
  • 34
  • 56

1 Answers1

0

As you may have figured it out, handling multi-level indexing in structures is a bit confusing. However, may find this helpful:

st(1).a.b.c=1;
st(2).a.b.c=2;
st(3).a.b.c=3;

checkLoop = 1;
while checkLoop
    if isstruct(st)
        fieldNm = fieldnames(st); % In case you have single field in each level
        st = [st(:).(fieldNm{1})];
    else
        checkLoop = 0;
    end
end

where3 = find(st == 3);
Ivea
  • 83
  • 7