필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
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'.

채택된 답변

Jan
Jan 2012년 9월 4일
편집: Jan 2012년 9월 4일
value = transpose([ft{:, 2}]);
index = (value >= 60) & (value <= 90) & strcmp(ft(:, 5), 'DFW');
ft2 = ft(index, :);

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2012년 9월 4일
편집: Azzi Abdelmalek 2012년 9월 4일
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
Jan
Jan 2012년 11월 14일
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)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by