And, as I suggested before, give each function as an additional argument the dataset. For example, using the files
and datasets
given in Neil's reply:
files = FileNames["~/Downloads/Moto_data/*.txt"] (* change as needed *)
datasets = Map[Import[#, "Data"] &, files];
vecMatDist[vec_?VectorQ, mat_?MatrixQ] := EuclideanDistance[vec, #] & /@ mat
nebs[i_, xy_] := Flatten@Position[vecMatDist[xy[[i]], Delete[xy, i]], _?(# < 12 &)]
lis[xy_] := nebs[#, xy] & /@ Range[Length@xy]
plotAll[xy_] := ListPlot[xy, AspectRatio -> Automatic,
PlotStyle -> PointSize[0.0051], PlotRange -> {{0, 1200}, {0, 700}}]
plotP[i_, xy_] := ListPlot[{xy[[i]]},
AspectRatio -> Automatic, PlotStyle -> Directive[PointSize[0.1], Black],
PlotRange -> {{1, 100}, {1, 100}}]
plotN2[i_, xy_] := ListPlot[Table[xy[[lis[xy][i][[j]]]], {j, 1, Length[lis[xy][i]]}],
AspectRatio -> Automatic,
PlotStyle -> Directive[PointSize[0.1], Red],
PlotRange -> {{lis[xy][[i]][[1]] - 20, lis[xy][[i]][[1]] + 20}, {lis[xy][[i]][[2]] - 20, lis[xy][[i]][[2]] + 20}}]
display[xy_] := (Print[plotAll[xy]];
Table[Show[plotN2[ii, xy], plotP[ii, xy]], {ii, 371, 374}])
display /@ datasets
Caution: This will fail because one of the data sets is too small to have 371 through 374th items!
Even for the longer data set, either the original plotting code or my implementation of nebs
, lis
, plotP
, or plotN2
is defective, as I see no points in the plots with plotP
,and plotN2
. Which is why I asked if my code for nebs
and lis
is faithfully implementing your intent.