Wolfram mathematica 在Mathematica中查找最近的时间戳
在Mathematica中,我必须找到最接近给定时间戳的时间戳。我有:Wolfram mathematica 在Mathematica中查找最近的时间戳,wolfram-mathematica,nearest-neighbor,Wolfram Mathematica,Nearest Neighbor,在Mathematica中,我必须找到最接近给定时间戳的时间戳。我有: alltrafotstamps = (DateList[#1]) & @@@ reddata[[All, 1]] 是什么给出了类似于时间戳列表的内容: {"2017-11-10 21:36:12.135", "2017-11-10 21:36:50.535", "2017-11-10 21:37:28.935", "2017-11-10 21:38:07.335", ...} 所以现在我要: Nearest[a
alltrafotstamps = (DateList[#1]) & @@@ reddata[[All, 1]]
是什么给出了类似于时间戳列表的内容:
{"2017-11-10 21:36:12.135", "2017-11-10 21:36:50.535",
"2017-11-10 21:37:28.935", "2017-11-10 21:38:07.335", ...}
所以现在我要:
Nearest[alltrafotstamps, DateList["2017-11-10 22:56:50.535"]]
我得到这个信息:
Nearest::neard: The default distance function does not give a real numeric distance when applied to the point pair 2017 and 2017-11-10 21:36:12.135.
是不是最近的人不能为时间戳做这件事,但只能为时间做这件事
alltrafotstamps = {
"2017-11-10 21:36:12.135",
"2017-11-10 21:36:50.535",
"2017-11-10 21:37:28.935",
"2017-11-10 21:38:07.335"};
target = "2017-11-10 21:37:00";
nearest = Nearest[
AbsoluteTime /@ alltrafotstamps,
AbsoluteTime[target]];
DateObject @@ nearest
DateList @@ nearest
它很管用,谢谢!很遗憾,Nearest不能直接在日期对象上工作。它可以工作,谢谢!遗憾的是,Nearest不能直接用于日期对象。
{2017, 11, 10, 21, 36, 50.535}