How can I filter struct according to strings in field?

15 visualizzazioni (ultimi 30 giorni)
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).

Risposta accettata

Guillaume
Guillaume il 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 Commenti
Candice Hermant
Candice Hermant il 9 Giu 2021
Modificato: Candice Hermant il 9 Giu 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Structures in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by