回复:在公式中使用 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
)
);
);