嗨,大家好。
我有這個非常複雜的問題在這裡解釋。所以基本上,這是數據表:

我應該使用JSL腳本創建一個名為“你周圍的總坐標”的列,通過想像在特定坐標周圍有8個方格(基本上不包括它自己的坐標),如下圖所示,其中小藍圈代表這個特定的坐標。因此,最大“您周圍的總坐標”為8。例如,如上圖所示,通過數字9998887,坐標(-2,1)的“你周圍的總坐標”為3,即(-2,2),( - 1,1)和(-1,0)。僅作為註釋,橫軸表示x坐標的偏移,同樣,縱軸表示x坐標的偏移。從上面的數據表中可以很容易地得出20“你周圍的總坐標”,但在我的實際任務中,有大約23,000多行需要處理。另外,我還應該根據上面數據表中顯示的9465371和9998887(它們具有相同的坐標)對數字進行排序,然後再處理“您周圍的總坐標”。

dt = current data table();
dt << New column ("Total Coordinates Around You",
numeric,
continuous,
formula (
For ( i = 1, i<= N Row(), i++,
(:Total Coordinates Around You = 0; munipulated_x = :X-Coordinate - 1; munipulated_y = Y-Coordinate - 1; j = 1; k = 1; formula (
For ( j = 1, j <= 3, j++,
(formula(
For ( k = 1, k <= 3, k++,
(formula( If (munipulated_x == :X-Coordinate & munipulated_y == :Y-Coordinate, :Total Coordinates Around You))
; munipulated_y ++)
)
) ; munipulated_x ++)
)
) ; :Total Coordinates Around You --)
)
)
);上面是我創建的一個腳本,我不知道為什麼這不能使用循環。有人可以告訴我有關如何處理這個問題的步驟和解決方案嗎?這個問題還有第二部分,一旦我完成第一部分,我將嘗試。如果對問題和解釋的清晰度有任何疑問,請允許我解釋,並再次原諒我的解釋。謝謝。
我不會在公式中執行它,因為它針對每一行運行,因此在公式內部循環將導致您非常慢。
這可能不是最好的方式,但似乎有效。 假設我理解正確並且您正在嘗試找到有多少瓷磚觸及您的開始瓷磚?
如果您正在嘗試這樣做,請告訴我。
Names default to here(1);
dt = New Table( "Example",
Add Rows( 20 ),
New Column( "Number",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values(
[9465371, 9465371, 9465371, 9465371, 9465371, 9465371, 9465371, 9465371,
9465371, 9465371, 9998887, 9998887, 9998887, 9998887, 9998887, 9998887,
9998887, 9998887, 9998887, 9998887]
)
),
New Column( "X-Coordinate",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values(
[2, 2, 1, 1, 0, 0, -1, -1, -2, -2, 2, 2, 1, 1, 0, 0, -1, -1, -2, -2]
)
),
New Column( "Y-Coordinate",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Selected,
Set Values( [2, 1, 0, -1, 3, 2, 1, 0, 2, 1, 2, 1, 0, -1, 3, 2, 1, 0, 2, 1] )
),
New Column("Adjacent", Numeric, "Continuous")
);
summarize(dt, byn = By(:Number));
for(i=1, i<=nitems(byn), i++,
sel = byn[i];
rows = dt << Get Rows Where(:Number == num(sel));
mat = dt[rows, {"X-Coordinate", "Y-Coordinate"}];
for(k = 1, k<=nrows(rows), k++,
row = rows[k];
// do a check that you're within the limit
adj = sqrt( (mat[k, 1] - mat[0, 1])^2 + (mat[k, 2] - mat[0, 2])^2) <= sqrt(2);
Column(dt, "Adjacent")[row] = nrows(Loc(adj)) - 1;
)
);我不確定我是否理解這個要求,但是如果你想找到給定點的相鄰點,你也可以使用'KDTable()'。例如:
Names Default To Here( 1 );
n = 100; // Size of square
// Make a table of x and y locations
dtx = AsTable((1::n)`, << Invisible);
dty = AsTable((1::n)`, << Invisible);
dt = dty << Join( With( dtx ), Cartesian Join );
Close(dtx, NoSave);
Close(dty, NoSave);
Column(dt, 1) << setName("x");
Column(dt, 2) << setName("y");
dt << deleteProperty("Source");
dt << setName("xy Locations");
// Put thes locations into a matrix
mat = dt << getAsMatrix;
tbl = KDTable( mat );
// Pick a point in the interior, so we don't need to decide on any boundary conditions
myX = RandomInteger(2, n-1);
myY = RandomInteger(2, n-1);
myRow = Loc(mat[0, 1] == myX & mat[0, 2] == myY);
myRow = myRow[1];
// Find the 8 nearest neighbours to the chosen point
{rows, dist} = tbl << K nearest rows( 8, myRow );
Show( myRow, rows );
// Check it worked
myXvals = Column(dt, "x")[myRow];
myYvals = Column(dt, "y")[myRow];
dt << NewColumn("Distance", Numeric, Continuous, Formula(sqrt((:x - myXvals)^2 +(:y - myYvals)^2)));
dt << selectRows(VConcat(myRow, rows`));
gb = dt << Graph Builder(
Size( 529, 453 ),
Show Control Panel( 0 ),
Variables( X( :x ), Y( :y ), Color( :Distance ) ),
Elements( Points( X, Y, Legend( 5 ) ) )
);