Intersection(A,B) not working for date
1 回表示 (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
採用された回答
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
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
2015 年 6 月 2 日
Since date vectors are row vectors, use the 'rows' option with intersect:
[C,ia, ib]=intersect(A,B,'rows');
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Time Series Objects についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!