Effacer les filtres
Effacer les filtres

How to row reduce matrix with character string and number interval?

1 vue (au cours des 30 derniers jours)
Tiffany Lee
Tiffany Lee le 4 Sep 2012
ft=
'2010-06-0100:13:33' [95] 'AAL1799' 'MD82' 'DFW'
'2010-06-0100:13:33' [60] 'EGF3258' 'E135' 'DFW'
'2010-06-0100:13:33' [40] 'EGF3345' 'E135' 'RTR'
'2010-06-0100:13:33' [86] 'AAL1951' 'MD83' 'DFW'
'2010-06-0100:13:33' [72] 'AAL1227' 'MD82' 'DFW'
I would like to reduce my matrix to only have rows with column 2 greater than or equal to 60 but less than or equal to 90 and have column 5 have 'DFW'.

Réponse acceptée

Jan
Jan le 4 Sep 2012
Modifié(e) : Jan le 4 Sep 2012
value = transpose([ft{:, 2}]);
index = (value >= 60) & (value <= 90) & strcmp(ft(:, 5), 'DFW');
ft2 = ft(index, :);

Plus de réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 4 Sep 2012
Modifié(e) : Azzi Abdelmalek le 4 Sep 2012
ft=ft(cell2mat(cellfun(@(x) x>=60 & x<=90,ft(:,2),'uni',false)),:)
ft=ft(cell2mat(cellfun(@(x) isequal(x,'DFW'),ft(:,5),'uni',false)),:)
  2 commentaires
Tiffany Lee
Tiffany Lee le 14 Nov 2012
thanks!
Jan
Jan le 14 Nov 2012
Both methods compute the same, but the first one is much faster and simpler:
strcmp(ft(:, 5), 'DFW')
cellfun(@(x) isequal(x,'DFW'), ft(:,5), 'uni', false)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Numeric Types dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by