MATLAB: How to find string structure elements

string findstructure

May be it is obvious, but I could not find out.
Let's say I have a structure 'people' with fields 'Surname' and 'Family_Name', like this:
people(1).Surname='Judit';
people(1).Family_Name='White';
people(2).Surname='Margaret';
people(2).Family_Name='Brown';
people(3).Surname='Judit';
people(3).Family_Name='Brown';
and so on, thousends.
How to find all Judits (or Browns)? I know I can make loops but is there any faster and shorter code?
Csaba

Best Answer

people(1).Surname='Judit';
people(1).Family_Name='White';
people(2).Surname='Margaret';
people(2).Family_Name='Brown';
people(3).Surname='Judit';
people(3).Family_Name='Brown';
%--------------------------------
a={people.Surname}
b={people.Family_Name}
id={'Judit' 'Brown'}
idx1=ismember(a,id)
idx2=ismember(b,id)
Related Question