How to filter a structure array based on a numeric value from a field?

Hi,
I have a structure array with different fields and I am trying to implement filters for it.
For fields with char variables, I am able to filter the structure with the following code.
trips_filter = trips(strcmp({trips.ser_id},'Arki'));
For fields with numeric values, I have not been able to find a way to filter it. I tried several ways to do it with no success, for example the following.
trips_filter2 = trips(trips.dir_id == 1);
For that command Im getting the 'Error using == Too many input arguments'.
Any help?
Thanks

 採用された回答

Stephen23
Stephen23 2020 年 3 月 26 日
編集済み: Stephen23 2022 年 2 月 23 日

1 投票

You will need to concatenate the comma-separated list into one numeric array, e.g.:
trips([trips.dir_id] == 1);
% ^ ^ Concatenate !
Read about how this works:

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeStructures についてさらに検索

製品

リリース

R2019b

タグ

質問済み:

2020 年 3 月 25 日

編集済み:

2022 年 2 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by