필터 지우기
필터 지우기

How to filter data?

조회 수: 2 (최근 30일)
Thor
Thor 2013년 1월 16일
Dear all,
I want to filter a matrix by its date vector. The datevector has the format: dd.mm.yyyy HH:MM:SS. I want to sum up all the data with the same month and year. How can I do that?

채택된 답변

Jan
Jan 2013년 1월 16일
dateAsString = {'31.02.2013 11:22:33'; '31.05.2013 11:22:33'}
dateAsVector = datevec(datestr, 'dd.mm.yyyy HH:MM:SS');
yearAndMonth = 100 * dateAsVector(:, 1) + dateAsVector(:, 2);
Now you get values like [201302, 201305] and summing can be done by accumarray directly.
  댓글 수: 2
Walter Roberson
Walter Roberson 2013년 1월 16일
You would probably not want to use those values as direct subscripts into accumarray: you would probably want to unique() them and use the indices. Otherwise your array is going to end up being up to 240000 long with not many entries used.
Jan
Jan 2013년 1월 16일
You are right, Walter, and even for a FOR loop approach using the indices obtained by UNIQUE is better.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matched Filter and Ambiguity Function에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by