0
$\begingroup$

I'm trying to group the points in a given direction as a function of the distance between each point, and then apply a function to the third coordinate. But I can only get these two directions, using this functions...

data = Prepend[
   Flatten[Table[{i, j, RandomReal[{1, 2}]}, {i, 0.5, 9.5, 1}, {j, 
      0.5, 9.5, 1}], 1], {"x", "y", "value"}];

list = Partition[Rest@data, 10]

makeList[list_] := 
 Table[{Drop[list, -k], Drop[list, k]}, {k, 1, Length[list] - 1}]

variog[list_] := Total[(Subtract @@@ list)^2]/(2 Length[list])

expVariog[list_, dist_, coord_] := Module[{p1, p2, p3, p4, p5 = {}},
  If[coord == "y",
   Do[p1 = (list[[i]])[[All, {2, 3}]]; 
    p2 = Flatten[(Partition[#, 2] & /@ Riffle @@@ makeList[p1]), 1]; 
    p3 = Table[
      If[Abs[(Subtract @@ p2[[i]])[[1]]] == dist, p2[[i]], 
       "Null"], {i, 1, Length[p2]}]; 
    p4 = Cases[#[[All, 2]] & /@ 
       Cases[p3, {_, _}], {_?NumberQ, _?NumberQ}]; 
    p5 = Append[p5, p4], {i, 1, Dimensions[list][[1]]}]; {dist, 
    variog@Flatten[p5, 1], Length[Flatten[p5, 1]]},
   Do[p1 = (list[[All, i]])[[All, {1, 3}]]; 
    p2 = Flatten[(Partition[#, 2] & /@ Riffle @@@ makeList[p1]), 1]; 
    p3 = Table[
      If[Abs[(Subtract @@ p2[[i]])[[1]]] == dist, p2[[i]], 
       "Null"], {i, 1, Length[p2]}]; 
    p4 = Cases[#[[All, 2]] & /@ 
       Cases[p3, {_, _}], {_?NumberQ, _?NumberQ}]; 
    p5 = Append[p5, p4], {i, 1, Dimensions[list][[2]]}]; {dist, 
    variog@Flatten[p5, 1], Length[Flatten[p5, 1]]}]
  ]

For example, using distance ranging from 1 to 5, in the directions given in the image 1 for all points.

Table[expVariog[list, k, "x"], {k, 1, 5}]

Table[expVariog[list, k, "y"], {k, 1, 5}]

Image 1

But I do not know how to generalize to weird directions as in image 2.

Image 2

$\endgroup$
  • 2
    $\begingroup$ Why not just project each point onto your desired direction by {a,b,c}.# & /@ mydata? $\endgroup$ – David G. Stork Jun 27 '17 at 1:23
  • $\begingroup$ Thanks for your tip, I'll work on it. $\endgroup$ – user48983 Jun 27 '17 at 20:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.