Intersection(A,B) not working for date

조회 수: 1 (최근 30일)
Meh
Meh 2015년 6월 2일
편집: Guillaume 2015년 6월 2일
I have A and B date vectors. I want to extract the common dates from both. I used:
[C,ia, ib]=intersection(A,B)
But it is giving me extremely few results than expected. Any solution?

채택된 답변

Ingrid
Ingrid 2015년 6월 2일
you should use a round before using using intersection to avoid floats not being equal to each other. If the dates are distinguishably by day (i.e. no hours given) you could use this
[C,ia, ib]=intersection(round(A),round(B))
  댓글 수: 1
Guillaume
Guillaume 2015년 6월 2일
편집: Guillaume 2015년 6월 2일
This answer would be more or less correct if the OP was using date numbers. But for accuracy down to the second, I would actually multiply the date numbers by 24x3600 before rounding.
As the OP is using date vectors though, Star's answer is the correct one.

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

추가 답변 (1개)

Star Strider
Star Strider 2015년 6월 2일
Since date vectors are row vectors, use the 'rows' option with intersect:
[C,ia, ib]=intersect(A,B,'rows');

카테고리

Help CenterFile Exchange에서 Time Series Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by