How can I filter struct according to strings in field?

17 Ansichten (letzte 30 Tage)
Zbynek Vlasic
Zbynek Vlasic am 12 Apr. 2017
Bearbeitet: Candice Hermant am 9 Jun. 2021
I have 1132x1 struct array with fields:
Geometry
BoundingBox
X
Y
STYP
In field STYP can be strings like EC030, EB010, EA040, etc... For me are only important rows (in struct) with string EA030 (in field STYP).

Akzeptierte Antwort

Guillaume
Guillaume am 12 Apr. 2017
wantedelements = yourstructure(strcmp({yourstructure.STYP}, 'EA030'))
{yourstructure.STYP} concatenate all the STYP fields into a cell array that you can then compare to your string to filter your array.
  2 Kommentare
Zbynek Vlasic
Zbynek Vlasic am 12 Apr. 2017
It works. Thank you
Candice Hermant
Candice Hermant am 9 Jun. 2021
Bearbeitet: Candice Hermant am 9 Jun. 2021
Hi!
I know this was answered a few years ago but is there a way to use this syntax with regex? What I mean is instead of giving a string like 'EA030' here, I would like to retrieve all the elements of a field that match a specific pattern, for instance all the text files.
I tried this:
wantedelement = foldersinfo(strcmp({foldersinfo.name}, '*.txt'))
but it returns an empty struct array.
Thank you very much for your help in advance.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

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