Ciao a tutti,
Ho un ciclo for che genera singole tabelle basate su elementi univoci in un elenco. Su ogni tabella generata, vengono eseguiti i calcoli e vengono aggiunte nuove colonne a ciascuna tabella. Si prega di vedere sotto per il codice e i miei commenti per ogni riga.
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
);La mia domanda è triplice:
- È possibile prendere la media dei valori in una colonna senza creare una nuova colonna per memorizzare i dati? Idealmente, la media sarebbe solo un singolo numero, non una colonna con lo stesso numero più e più volte. Forse semplicemente sputando in una nuova tabella, lista o qualcos'altro, basta rendere il codice/tabella più leggibile e meno gonfio.
Questo fa parte dell'output del codice precedente. Ottengo solo colonne con lo stesso numero più e più volte per le medie calcolate.

- Per ogni tabella di dati creata dal ciclo for, vorrei che i dati nelle colonne calcolate fossero archiviati in una sorta di tabella o elenco in modo che non vengano sovrascritti con ogni nuova iterazione del ciclo for.
- La funzione matrice associativa sta arrotondando i dati nella colonna. Può essere impostato per non farlo?
Ho allegato un esempio dell'output del codice. Per semplicità, ho ristretto MaskList a 1 elemento, quindi il ciclo for viene eseguito solo una volta.
Qualsiasi aiuto è apprezzato.
Grazie.
Credo che lo script seguente ti fornirà la tabella di dati separata che desideri con i mezzi per ciascuna maschera.Crea le nuove colonne arrotondate nella tabella dt3, quindi esegue solo una piattaforma di riepilogo (tabelle=>Riepilogo) sulle colonne arrotondate.

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" )
);
Potresti anche voler guardare la piattaforma Tabulate (Analyze => Tabulate), che potrebbe anche essere utilizzata
