How can I filter struct according to strings in field?

15 ビュー (過去 30 日間)
Zbynek Vlasic
Zbynek Vlasic 2017 年 4 月 12 日
編集済み: Candice Hermant 2021 年 6 月 9 日
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).

採用された回答

Guillaume
Guillaume 2017 年 4 月 12 日
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 件のコメント
Zbynek Vlasic
Zbynek Vlasic 2017 年 4 月 12 日
It works. Thank you
Candice Hermant
Candice Hermant 2021 年 6 月 9 日
編集済み: Candice Hermant 2021 年 6 月 9 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by