皆さんこんにちは。
私はここで説明するためにこの非常に複雑な質問をします。つまり、これはデータテーブルです。

下の図に示すように、JSLスクリプトを使用して特定の座標の周囲に8つの正方形(基本的にそれ自体の座標を除く)があることを想像して、「自分の周囲の合計座標」という列を作成します。この特定の座標を表します。したがって、最大「あなたの周りの合計座標」は8です。たとえば、上の図に示すように、9998887という数字では、座標(-2,1)の「あなたの周囲の合計座標」は3になります。これは(-2,2)、(-1,1)および(-1,0) ちなみに、横軸はx座標のシフトを表し、縦軸はx座標のシフトを表します。上のデータ表から、20個の「あなたの周りの合計座標」を作るのは簡単ですが、私の実際の仕事では、扱うべき約23,000を超える行があります。また、もう1つ、「あなたの周りの合計座標」を処理する前に、上のデータ表にそれぞれ示されている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 --)
)
)
);上記のスクリプトは私が作成したものですが、ループを使用してこれを実行できない理由はわかりません。誰かがこの問題に対処する方法についての手順と解決策について私を啓発することはできますか?この質問には2番目の部分があり、最初の部分が終わったら試してみます。特に質問と説明の明確さについて疑問がある場合は私に説明させてください、そしてもう一度説明をお願いします。ありがとうございました。
行ごとに実行されるので、式では行いません。式の内側をループすると、処理が遅くなります。
これはおそらく最善の方法ではありませんが、うまくいくようです。 私は正しく理解していて、あなたは何枚のタイルがあなたの最初のタイルに触れているのか見つけようとしていると仮定しますか?
これがあなたがやろうとしていることであるかどうか私に知らせてください。
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 ) ) )
);