How to find string structure elements?

24 Ansichten (letzte 30 Tage)
Csaba
Csaba am 2 Mai 2017
Beantwortet: upol am 10 Jan. 2019
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

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 2 Mai 2017
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)

Weitere Antworten (1)

upol
upol am 10 Jan. 2019
Why this gives problem in C Coder. Error: Directly accessing field or property of nonscalar struct or object not supported for code generation.
s1=string({OPS_FLT(:).ACFT_ID})
s2=OPS_FLT(2).ACFT_ID
uuindex=find(strcmpi(s1,s2))
({OPS_FLT(:).ACFT_ID}) has already been defined as
OPS_FLT(1).ACFT_ID="apple"
OPS_FLT(2).ACFT_ID="orange"
I am trying to find orange from the array. It works in Matlab but not in C Coder

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by