Hallo alle,
Ich habe eine for-Schleife, die einzelne Tabellen basierend auf eindeutigen Elementen in einer Liste generiert. Für jede generierte Tabelle werden Berechnungen durchgeführt und jeder Tabelle werden neue Spalten hinzugefügt. Unten finden Sie den Code und meine Kommentare zu jeder Zeile.
MaskList = Associative Array(Column(dt3, "mask") << Get Values) << Get Keys; // from dt3, puts unique masks into a list, removes duplicates
show(MaskList); // show for debugging purposes, to be viewed in Log window
// This loop creates a new table for each unique mask in MaskList
For (i = 1, i <= N Items(MaskList), i++,
dt3 << Select Where( :mask == MaskList[i]); // selects the rows of the chosen mask at the i-th position in MaskList
dt4 = dt3 << Subset (Output Table("Mask Table"), Get Selected Rows, "visible"); // outputs a separate table for each unique mask
dt4 << New Column("new_x_offset", Numeric, "Continuous", Format( "Best", 12 ), Formula( Round( :best_x_offset, 2 ) )); // calculation and new column
dt4 << New Column("new_y_offset", Numeric, "Continuous", Format( "Best", 12 ), Formula( Round( :best_y_offset, 2 ) )); // calculation and new column
dt4 << New Column("new_xscl", Numeric, "Continuous", Format( "Best", 12 ), Formula( Round( 1 - (:xscl - (-0.5)), 2 ) )); // calculation and new column
dt4 << New Column("new_yscl", Numeric, "Continuous", Format( "Best", 12 ), Formula( Round( 1 - (:yscl - (-0.5)), 2 ) )); // calculation and new column
dt4 << New Column("new_ort", Numeric, "Continuous", Format( "Best", 12 ), Formula( Round( 1 - (:ort), 2 ) )); // calculation and new column
dt4 << New Column("new_rotg", Numeric, "Continuous", Format( "Best", 12 ), Formula( Round( 1 - (:rotg), 2 ) )); // calculation and new column
dt4 << New Column("new_mag", Numeric, "Continuous", Format( "Best", 12 ), Formula( Round( 1 - (:mag - (-1.0)), 2 ) )); // calculation and new column
dt4 << New Column("new_rotf", Numeric, "Continuous", Format( "Best", 12 ), Formula( Round( 1 - (:rotf - (-1.0)), 2 ) )); // calculation and new column
dt4 << New Column("Mean_x_offset", Numeric, "Continuous", Format( "Best", 12 ), Formula( Col Mean( :new_x_offset ) )); // take average of values in column new_x_offset
dt4 << New Column("Mean_y_offset", Numeric, "Continuous", Format( "Best", 12 ), Formula( Col Mean( :new_y_offset ) )); // take average of values in column new_y_offset
dt4 << New Column("Mean_new_xscl", Numeric, "Continuous", Format( "Best", 12 ), Formula( Col Mean( :new_xscl ) )); // take average of values in column new_xscl
dt4 << New Column("Mean_new_yscl", Numeric, "Continuous", Format( "Best", 12 ), Formula( Col Mean( :new_yscl ) )); // take average of values in column new_yscl
dt4 << New Column("Mean_new_ort", Numeric, "Continuous", Format( "Best", 12 ), Formula( Col Mean( :new_ort ) )); // take average of values in column new_ort
dt4 << New Column("Mean_new_rotg", Numeric, "Continuous", Format( "Best", 12 ), Formula( Col Mean( :new_rotg ) )); // take average of values in column new_rotg
dt4 << New Column("Mean_new_mag", Numeric, "Continuous", Format( "Best", 12 ), Formula( Col Mean( :new_mag ) )); // take average of values in column new_mag
dt4 << New Column("Mean_new_rotf", Numeric, "Continuous", Format( "Best", 12 ), Formula( Col Mean( :new_rotf ) )); // take average of values in column new_rotf
Output_x_offset = Associative Array(Column(dt4, "Mean_x_offset") << Get Values) << Get Keys; // saves average x_offset, removes duplicates
Output_y_offset = Associative Array(Column(dt4, "Mean_y_offset") << Get Values) << Get Keys; // saves average y_offset, removes duplicates
Output_xscl = Associative Array(Column(dt4, "Mean_new_xscl") << Get Values) << Get Keys; // saves average xscl, removes duplicates
Output_yscl = Associative Array(Column(dt4, "Mean_new_yscl") << Get Values) << Get Keys; // saves average yscl, removes duplicates
Output_ort = Associative Array(Column(dt4, "Mean_new_ort") << Get Values) << Get Keys; // saves average ort, removes duplicates
Output_rotg = Associative Array(Column(dt4, "Mean_new_rotg") << Get Values) << Get Keys; // saves average rotg, removes duplicates
Output_mag = Associative Array(Column(dt4, "Mean_new_mag") << Get Values) << Get Keys; // saves average mag, removes duplicates
Output_rotf = Associative Array(Column(dt4, "Mean_new_rotf") << Get Values) << Get Keys; // saves average rotf, removes duplicates
);Meine Frage ist dreifach:
- Ist es möglich, den Durchschnitt der Werte in einer Spalte zu ermitteln, ohne eine neue Spalte zum Speichern der Daten zu erstellen? Im Idealfall wäre der Durchschnitt nur eine einzelne Zahl und nicht eine Spalte mit immer wieder derselben Zahl. Vielleicht einfach in eine neue Tabelle, Liste oder etwas anderes hineinspucken, um den Code/die Tabelle einfach lesbarer und weniger aufgeblasen zu machen.
Dies ist Teil der Ausgabe des obigen Codes. Ich bekomme immer wieder Spalten mit der gleichen Nummer für die berechneten Durchschnittswerte.

- Für jede von der for-Schleife erstellte Datentabelle möchte ich, dass die Daten in den berechneten Spalten in einer Art Tabelle oder Liste gespeichert werden, damit sie nicht bei jeder neuen Iteration der for-Schleife überschrieben werden.
- Die assoziative Array-Funktion rundet die Daten in der Spalte. Kann man das so einstellen, dass das nicht passiert?
Ich habe ein Beispiel für die Ausgabe des Codes angehängt. Der Einfachheit halber habe ich MaskList auf ein Element beschränkt, sodass die for-Schleife nur einmal ausgeführt wird.
Jede Hilfe wird geschätzt.
Danke.
Ich glaube, dass das folgende Skript Ihnen die gewünschte separate Datentabelle mit den Mitteln für jede Maske liefert.Es erstellt die neuen abgerundeten Spalten in der dt3-Tabelle und führt dann einfach eine Zusammenfassungsplattform (tables=>Summary) für die abgerundeten Spalten aus.

Names Default To Here( 1 );
dt3 = Data Table( "dt3" );
dt3 << New Column( "new_x_offset", Numeric, "Continuous", Format( "Best", 12 ), Formula( Round( :best_x_offset, 2 ) ) ); // calculation and new column
dt3 << New Column( "new_y_offset", Numeric, "Continuous", Format( "Best", 12 ), Formula( Round( :best_y_offset, 2 ) ) ); // calculation and new column
dt3 << New Column( "new_xscl", Numeric, "Continuous", Format( "Best", 12 ), Formula( Round( 1 - (:xscl - (-0.5)), 2 ) ) ); // calculation and new column
dt3 << New Column( "new_yscl", Numeric, "Continuous", Format( "Best", 12 ), Formula( Round( 1 - (:yscl - (-0.5)), 2 ) ) ); // calculation and new column
dt3 << New Column( "new_ort", Numeric, "Continuous", Format( "Best", 12 ), Formula( Round( 1 - (:ort), 2 ) ) ); // calculation and new column
dt3 << New Column( "new_rotg", Numeric, "Continuous", Format( "Best", 12 ), Formula( Round( 1 - (:rotg), 2 ) ) ); // calculation and new column
dt3 << New Column( "new_mag", Numeric, "Continuous", Format( "Best", 12 ), Formula( Round( 1 - (:mag - (-1.0)), 2 ) ) ); // calculation and new column
dt3 << New Column( "new_rotf", Numeric, "Continuous", Format( "Best", 12 ), Formula( Round( 1 - (:rotf - (-1.0)), 2 ) ) ); // calculation and new column
dtSum = dt3 << Summary(
Group( :mask ),
Mean( :new_x_offset, :new_y_offset, :new_xscl, :new_yscl, :new_ort, :new_rotg, :new_mag, :new_rotf ),
Freq( "None" ),
Weight( "None" )
);
Vielleicht möchten Sie sich auch die Tabulate-Plattform (Analyze=>Tabulate) ansehen, die ebenfalls verwendet werden könnte

Danke schön. Beide Optionen funktionieren hervorragend.
Ich frage mich, ob es eine Möglichkeit gibt, die dtSum-Tabellen (oder die Ausgabe von Tabulate) in einer einzigen Tabelle zu kombinieren.