在“選擇位置”和“列中選擇名稱”中使用參數你好,
我需要一個由X和Y兩列組成的數據表,選擇數據表的幾行並命名選擇。 這對應於在xy笛卡爾空間中選擇二十個矩形,並用數字(從1到20)命名它們(我正在處理圖像)。
我寫了一個腳本,但是不起作用。 我認為我需要解決兩個問題:1)如何使用參數“ select where”的參數,請參閱X1,X2,..? 2)如何在“列中名稱選擇”的參數中使用參數,請參見n_patch?
非常感謝。
這是腳本:
dt = Current Data Table();
X0 = 2332;
Y0 = 558;
n_patch = 0;
delta_x = 100;
delta_y = 100;
dist_y = 488;
dist_x = 656;
L_x = 500;
L_y = 500;
For( n_x = 1, n_x <= 4, n_x++,
For( n_y = 1, n_y <= 5, n_y++,
Xc = X0 - (n_x - 1) * (dist_x) + L_x / 2;
Yc = Y0 + (n_y - 1) * (dist_y) + L_y / 2;
n_patch = n_patch + 1;
X1 = Xc - delta_x;
X2 = Xc + delta_x;
Y1 = Yc - delta_y;
Y2 = Yc + delta_y;
dt << Row Selection(
Select where( (:X >= X1 & :X <= X2) & (Y >= Y1 & Y <= Y2) )
);
dt << Name Selection in Column(
Column Name( "Patch#" ),
Selected( ("n_patch") ),
Unselected( "" )
);
)
);
數據表腳本編寫回复:在“選擇位置”和“列中選擇名稱”中使用參數你好@MFVIT ,
您需要確保在腳本中評估了X1和Y1的值,而不是在數據表本身中查找內容。這個問題在使用Eval插入,Eval Expr,解析和替換將一個表達式插入另一個表達式。 您可以通過使用Eval(Eval Expr())來確保發生這種情況。 這是將代碼與示例數據表結合使用的示例。
Names default to here(1);
dt = New Table( "Example Data",
Add Rows( 10000 ),
New Column( "X", Numeric, "Continuous", Format( "Best", 12 ),
Formula( Random Uniform( 0, 10000 ) ) ),
New Column( "Y", Numeric, "Continuous", Format( "Best", 12 ),
Formula( Random Uniform( 0, 10000 ) ) )
);
X0 = 2332;
Y0 = 558;
n_patch = 0;
delta_x = 100;
delta_y = 100;
dist_y = 488;
dist_x = 656;
L_x = 500;
L_y = 500;
For( n_x = 1, n_x <= 4, n_x++,
For( n_y = 1, n_y <= 5, n_y++,
Xc = X0 - (n_x - 1) * (dist_x) + L_x / 2;
Yc = Y0 + (n_y - 1) * (dist_y) + L_y / 2;
n_patch = n_patch + 1;
X1 = Xc - delta_x;
X2 = Xc + delta_x;
Y1 = Yc - delta_y;
Y2 = Yc + delta_y;
Eval( Eval Expr(
dt << Row Selection(
Select where( (:X >= Expr( X1 ) & :X <= Expr( X2 )) & (:Y >= Expr( Y1 ) & :Y <= Expr( Y2 ) ) )
);
) );
dt << run formulas;
dt << Name Selection in Column(
Column Name( "Patch#" || char( n_patch ) ),
Selected( "n_patch = " || char( n_patch ) ),
Unselected( "" )
);
)
);回复:在“選擇位置”和“列中選擇名稱”中使用參數您好,非常感謝您的及時答复。
您的代碼對我非常有用,我認為我的方法是正確的。 但是,仍然有些東西行不通。
我嘗試運行您的代碼,但發現它添加了許多名為“ Patch#1”,“ Patch#2”等的列,因此我更改了該行
Column Name( "Patch#" || char( n_patch ) )
和
Column Name( "Patch#")
因為我只想要一列名稱為Patch#的列。
但是代碼沒有選擇我希望選擇的內容。 它僅選擇patch5、10、15和20,而不選擇其他補丁,而且所選行不對應於補丁。
因此,我不確定選擇命令是否正常工作。
非常感謝您的幫助。
馬塞洛。
回复:在“選擇位置”和“列中選擇名稱”中使用參數您可能使用的是JMP的舊版本,所以我不確定它們是否適合您(不使用列中的“行選擇”或“名稱選擇”)。
您可以通過<<獲取感興趣的行,然後在column()[rows]中設置值。
dt << New Column("Patch#", Character);
For( n_x = 1, n_x <= 4, n_x++,
For( n_y = 1, n_y <= 5, n_y++,
Xc = X0 - (n_x - 1) * (dist_x) + L_x / 2;
Yc = Y0 + (n_y - 1) * (dist_y) + L_y / 2;
n_patch = n_patch + 1;
X1 = Xc - delta_x;
X2 = Xc + delta_x;
Y1 = Yc - delta_y;
Y2 = Yc + delta_y;
wantedRows = dt << get rows where(:X >= X1 & :X <= X2 & :Y >= Y1 & :Y <= Y2);
Column(dt, "Patch#")[wantedRows] = char(n_patch);
)
);