Hallo allerseits.
Ich habe diese sehr komplizierte Frage hier zu erklären. Im Grunde ist dies die Datentabelle:

Ich soll eine Spalte mit dem Namen "Total Coordinates Around You" mithilfe von JSL-Skript erstellen, indem ich mir vorstelle, dass die jeweilige Koordinate aus 8 Quadraten besteht (im Grunde genommen ohne die eigene Koordinate) repräsentiert diese bestimmte Koordinate. Somit beträgt die maximale "Gesamtzahl der Koordinaten um Sie herum" 8. Wie in der obigen Abbildung gezeigt, hat die Koordinate (-2,1) beispielsweise eine "Gesamtzahl der Koordinaten um Sie herum" von 3, dh (-2,2), (-1,1) und (-1,0). Nur für eine Anmerkung repräsentiert die horizontale Achse eine Verschiebung in der x-Koordinate und ebenso repräsentiert die vertikale Achse eine Verschiebung in der x-Koordinate. Aus der obigen Datentabelle ist es einfach, 20 "Gesamtkoordinaten um Sie herum" zu erstellen, aber bei meinen eigentlichen Aufgaben müssen über 23.000 Zeilen bearbeitet werden. Außerdem soll ich die Zahlen wie 9465371 und 9998887 in der obigen Datentabelle sortieren (sie haben die gleichen Koordinaten), bevor ich an den "Gesamtkoordinaten um dich herum" arbeite.

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 --)
)
)
);Oben ist ein Skript, das ich erstellt habe. Ich bin mir nicht sicher, warum dies mit Schleifen nicht funktioniert. Kann mich jemand über die Schritte und Lösungen zum Umgang mit diesem Problem aufklären? Zu dieser Frage gibt es einen zweiten Teil, den ich versuchen werde, sobald ich meinen ersten Teil erledigt habe. Lassen Sie mich erklären, falls Zweifel an der Klarheit der Frage und Erklärung bestehen, und entschuldigen Sie mich noch einmal für die Erklärung. Vielen Dank.
Ich würde es nicht in einer Formel tun, da es für jede Zeile ausgeführt wird. Wenn Sie also in einer Formel eine Schleife ausführen, werden Sie ziemlich langsam.
Dies ist wahrscheinlich nicht der beste Weg, aber es scheint zu funktionieren. Vorausgesetzt, ich verstehe es richtig und du versuchst herauszufinden, wie viele Kacheln dein Anfangsplättchen berühren?
Lassen Sie mich wissen, ob Sie dies versuchen.
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;
)
);Ich bin nicht sicher, ob ich die Anforderung verstehe, aber wenn Sie benachbarte Punkte zu einem bestimmten Punkt suchen möchten, können Sie auch 'KDTable ()' verwenden. Zum Beispiel:
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 ) ) )
);