Matlab中的成员检查和日期范围检查
我有 2 个具有相同 ID 的矩阵。我需要从 mat1
中提取 ID 行,这些 ID 的日期在 mat2
中的日期的 ±5 天内。对于 mat2
也进行相同的操作。请查看此处的数据:UNIQCols = [1 2] ;日期列 = [3] ;值列 = [4] ; dayRange = +- 15天
。
% UniqCol Date Value
mat1 = [2001 2 733427 1001 ;
2001 2 733793 2002 ;
2001 2 734582 2003 ;
3001 1 734220 30 ;
3001 1 734588 20 ;];
mat2 = [2001 2 733790 7777 ;
2001 2 734221 2222 ;
3001 1 734220 10 ;
3001 1 734588 40 ;] ;
ans1 = [2001 2 733793 2002 ; 3001 1 734220 30 ; 3001 1 734588 20 ] ;
ans2 = [2001 2 733790 7777 ; 3001 1 734220 10 ; 3001 1 734588 40 ] ;
这需要是矢量化操作! ID 按日期升序排列。日期可以按 Q 或按年分开。所以范围总是 << (日期2-日期1)请帮忙,谢谢!
I have 2 matrices with the SAME IDs. I need to extract those rows of IDs from mat1
which have their dates within say ±5 days of the dates in the mat2
. Same operation for mat2
as well. Please see the data here: UNIQCols = [1 2] ; dateCol = [3] ; valueCol = [4] ; dayRange = +- 15days
.
% UniqCol Date Value
mat1 = [2001 2 733427 1001 ;
2001 2 733793 2002 ;
2001 2 734582 2003 ;
3001 1 734220 30 ;
3001 1 734588 20 ;];
mat2 = [2001 2 733790 7777 ;
2001 2 734221 2222 ;
3001 1 734220 10 ;
3001 1 734588 40 ;] ;
ans1 = [2001 2 733793 2002 ; 3001 1 734220 30 ; 3001 1 734588 20 ] ;
ans2 = [2001 2 733790 7777 ; 3001 1 734220 10 ; 3001 1 734588 40 ] ;
This needs to be a vectorized operation! The IDs are ordered in increasing order of dates. Dates are either separated on Q or Annual basis. So the range will be always << (date2-date1) Please help and thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个基于我在评论中提到的类似问题的函数。请记住,您的矩阵必须按日期排序。
和测试脚本:
我还没有尝试过任何矢量化解决方案来解决您的问题。如果您遇到任何问题,请尝试针对此解决方案并检查时间和内存消耗(包括排序步骤)。
Here is a function based on similar question I mentioned in my comments. Remember your matrices has to be sorted by date.
And the test script:
I haven't tried any vectorized solution for your problem. If you get any try it against this solution and check the timing and memory consumption (include sorting step).