How can I filter struct according to strings in field?

17 vues (au cours des 30 derniers jours)
Zbynek Vlasic
Zbynek Vlasic le 12 Avr 2017
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).

Réponse acceptée

Guillaume
Guillaume le 12 Avr 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 commentaires
Zbynek Vlasic
Zbynek Vlasic le 12 Avr 2017
It works. Thank you
Candice Hermant
Candice Hermant le 9 Juin 2021
Modifié(e) : Candice Hermant le 9 Juin 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by