在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[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.会不会是最近的时间戳不能这样做,而只能做时间?
发布于 2017-11-17 06:06:07
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{2017,11,10,21,36,50.535}
https://stackoverflow.com/questions/47335764
复制相似问题