I am just curious that there is any better way to write the code to search the nearest value than what I wrote below
peaks={{127, 1}, {133, 0.992}, {139, 1}, {1762, 0.984}};
DeleteDuplicates[
Table[
Select[peaks,
(peaks[[i, 2]] - 0.1 <= #[[2]] <= peaks[[i, 2]] + 0.1) &&
(peaks[[i, 1]] - 20 <= #[[1]] <= peaks[[i, 1]] + 20)
&]
, {i, 1, Length[peaks]}]]
(*Output*)
{{{127, 1}, {133, 0.992}, {139, 1}}, {{1762, 0.984}}}
I think there will be much simpler and easier way to write in mathematica... Any help?
Edit
I try to gather the value by the near position
You can see that three points are All in blue point, and one point is at yellow dot. I just want to find this cluster
Nearest
. But please describe what you want the code to do. $\endgroup$ – corey979 Oct 4 '16 at 15:30Gather[peaks, And[Abs[#1[[1]] - #2[[1]]] < 20, Abs[#1[[2]] - #2[[2]]] < 0.1] &]
, assuming I understand your question. But I echo @corey979: Can you explain what it is you're trying to do? $\endgroup$ – march Oct 4 '16 at 15:32