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

143 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Stephen23
Stephen23 el 26 de Mzo. de 2020
Editada: Stephen23 el 23 de Feb. de 2022
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:

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by