回覆:在公式中使用 for 迴圈變數有幾個問題
這
Column[ l ]
您指定的語法不正確。Column 是一個函數 (),而不是矩陣 [],因此需要將其指定為
Column( l )
接下來,公式將與您分配的值有問題。根據您的公式,有些情況下不會分配任何值。由於 JMP 公式傳回最後指派的值,因此您需要為每種情況為公式明確指派一個值。在我的公式版本中,我使用變數 X 來分配您的邏輯。我將該值初始化為缺失值,然後由您的 If() 邏輯指派 X。然後,我透過簡單地添加來確保 X 的計算值是最後處理的值
x;
作為公式中的最後一條語句。
For( k = 40, k <= 54, k += 2,
x1 = 1;
x2 = 8;
y1 = 40;
y2 = 54;
m = (y2 - y1) / (x2 - x1);
c = y2 - (m * x1);
l = (k - c) / m;
dt << New Column( "Test" || Char( k ),
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula(
x = .;
If( :Strobe == 1,
If(
:Tested Variable == 0 | :Tested Plane == 1,
If( Left( Right( :"x"n, Column(l) ) ),
1
) == "1",
x = 1,
Left( Right( :"x"n, (l) ), 1 ) == "0",
x = 0,
),
);
x;
)
);
)
最後,在討論問題中輸入 JSL 時,請使用
圖標,以便社區成員更容易閱讀 JSL
在公式中使用 for 迴圈變數嘗試使用此腳本,但變數“l”不起作用,只有變數“k”起作用。 無論如何要解決這個問題嗎?
For( k = 40, k <= 54, k += 2,
x1 = 1;
x2 = 8;
y1 = 40;
y2 = 54;
m = (y2 - y1) / (x2 - x1);
c = y2 - (m * x1);
l = (k - c) / m;
dt << New Column( "Test" || Char( k ),
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula(
If( :Strobe == 1,
If(
:Tested Variable == 0 | :Tested Plane == 1,
If( Left( Right( :"x"n, Column[l] ) ), 1 ) == "1",
1, Left( Right( :"x"n, (l) ), 1 ) == "0",
0,
),
)
)
);
)自動化和腳本編寫回覆:在公式中使用 for 迴圈變數好的,當然,下次會使用該圖示。 順便說一句,腳本不起作用。 也許我應該進一步詳細說明我面臨的問題是什麼
我有一列包含 8 位元二進制數,例如 x="00101101"
那麼當我的變數 k 不同時,從列 x 讀出的位元應該不同
\\k start 40, For each loop will add 2
For( k = 40, k <= 54, k += 2,
x1 = 1;
x2 = 8;
y1 = 40;
y2 = 54;
m = (y2 - y1) / (x2 - x1);
c = y2 - (m * x2);
l = (k - c) / m;
\\l is calculated based on k\
\\Tested variable & Column x & Strobe are the column in my data set
\\If k=40, then the readout will be 1st bit from the right of column x;
\\If k=40, then the readout will be 8th bit from the right of column x;
dt << New Column( "Test" || Char( k ),
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula(
If( :Strobe == 1,
If(
:Tested Variable == 0 | :Tested Variable == 1,
If( Right( :"x"n, Column(l) ) ) == "1",
1, Right( :"x"n, (l) )== "0",
0,
),
)
)
);
)我面臨的問題是 jmp 無法辨識我想要讀出的位,無論我將 Column(l), l 放入 for 迴圈中
回覆:在公式中使用 for 迴圈變數如果您能附上範例資料表,將會很有幫助。
根據您的進一步解釋,嘗試更改
If( Right( :"x"n, Column(l) ) ) == "1"
到
If( Right( :"x"n, as Column( "Column" || char(l) )== "1"
回覆:在公式中使用 for 迴圈變數嗨吉姆,這是數據表,我將我期望在數據表中看到的內容放入其中。 列資料描述什麼是「l」值以及它來自「x」的哪個值
回覆:在公式中使用 for 迴圈變數謝謝吉姆,我認為它可以工作,但列印輸出會略有不匹配。 在公式中的“_l_”後面加上“,1”時效果很好。 我在這裡附上了完整的 jsl 腳本
Names Default To Here( 1 );
dt = Current Data Table();
//k start 40, For each loop will add 2
For( k = 40, k <= 54, k += 2,
x1 = 1;
x2 = 8;
y1 = 40;
y2 = 54;
m = (y2 - y1) / (x2 - x1);
c = y2 - (m * x2);
l = (k - c) / m;
//l is calculated based on k\
//Tested variable & Column x & Strobe are the column in my data set
//If k = 40;, then the readout will be 1st bit from the right of column x;
//If k = 40;,then the readout will be 8th bit from the right of column x;
// The variable l needs to be fully parsed in the formula, so that if the
// value of l changes, it does not change previous formulas
Eval(
Substitute(
Expr(
dt << New Column( "Test" || Char( k ),
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula(
theVal = .;
If( :Strobe == 1,
If( :Tested Variable == 0 | :Tested Variable == 1,
theVal = Num( Substr( :x, _l_ ,1) )
)
);
theVal;
)
)
),
Expr( _l_ ), l
)
);
);回覆:在公式中使用 for 迴圈變數你是對的,這是我的錯。我會更正我的條目。
回覆:在公式中使用 for 迴圈變數下面的腳本似乎可以工作。您提供的腳本使用 \\ 作為註解起始符,其中 // 是正確的語法。
真正的工作公式實際上可以歸結為使用 Substr() 函數。
新增 Eval(Substitute(Expr())) 部分只是將 l 變數的值改為 l 的實際值,而不是透過變數來引用該值。
Names Default To Here( 1 );
dt = Current Data Table();
//k start 40, For each loop will add 2
For( k = 40, k <= 54, k += 2,
x1 = 1;
x2 = 8;
y1 = 40;
y2 = 54;
m = (y2 - y1) / (x2 - x1);
c = y2 - (m * x2);
l = (k - c) / m;
//l is calculated based on k\
//Tested variable & Column x & Strobe are the column in my data set
//If k = 40;, then the readout will be 1st bit from the right of column x;
//If k = 40;,then the readout will be 8th bit from the right of column x;
// The variable l needs to be fully parsed in the formula, so that if the
// value of l changes, it does not change previous formulas
Eval(
Substitute(
Expr(
dt << New Column( "Test" || Char( k ),
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula(
theVal = .;
If( :Strobe == 1,
If( :Tested Variable == 0 | :Tested Variable == 1,
theVal = Num( Substr( :x, _l_ , 1 ) )
)
);
theVal;
)
)
),
Expr( _l_ ), l
)
);
);