For versions prior to 10.1 the following returns a error message
timedat = {1.1, 2, 3.3};
equalTime = {1, 2, 3};
Flatten@Nearest[timedat, equalTime]
Nearest::dmtch: The dimension of {1.1,2,3.3} and {1,2,3} does not match. >>
A workaround is
Flatten[Nearest[timedat, #] & /@ equalTime]
(* {1.1, 2, 3.3}*)
However, I was thinking if there is a way to modify the default behavior of Nearest
, for versions prior to 10.1, in order to achieve the better performance of the current version.
That is,
Flatten@Nearest[timedat, equalTime]
should return
{1.1, 2, 3.3}
Flatten@With[{n = Nearest[#1]}, n /@ #2] &[timedat[[All, 1]], equalTime]
$\endgroup$ – ciao Sep 25 '15 at 9:23myNearest[l1_List, l2_List] := With[{n = Nearest@l1}, n /@ l2]
if you want it as a generalized function. You could unprotectNearest
and overload it, but generally, that's a seriously bad idea... $\endgroup$ – ciao Sep 25 '15 at 9:30