Re: Usar variable de bucle for en una fórmulaUn par de cuestiones
El
Column[ l ]
La sintaxis que especificaste es incorrecta.La columna es una función (), no una matriz [] por lo tanto, debe especificarse como
Column( l )
A continuación, la fórmula tendrá un problema con el valor que estás asignando.Dada su fórmula, hay casos en los que no se asignará ningún valor.Dado que una fórmula JMP devuelve el último valor asignado, es necesario asignar explícitamente un valor a la fórmula para cada caso.En mi versión de tu fórmula, estoy usando una variable X para asignarle tu lógica.Inicializo el valor con un valor faltante y luego su lógica If() asigna X.Luego aseguro que el valor calculado de X es el último valor procesado, simplemente sumando
x;
como última declaración de la fórmula.
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;
)
);
)
Finalmente, al ingresar JSL en una pregunta de discusión, utilice el
icono para que el JSL sea más fácil de leer para los miembros de la comunidad
Usar la variable de bucle en una fórmulaProbando con este script pero la variable "l" no funciona, solo funciona la variable "k". ¿Alguna forma de resolver esto?
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,
),
)
)
);
)Automatización y secuencias de comandosRe: Usar variable de bucle for en una fórmulaOk, claro, usaré el ícono la próxima vez. Por cierto, el guión no funciona. Tal vez debería explicar más cuáles son los problemas que enfrenté.
Tengo una columna con un número binario de 8 bits, por ejemplo x="00101101"
Entonces, cuando mi variable k es diferente, el bit leído de la columna x debería ser diferente
\\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,
),
)
)
);
)El problema que enfrenté es que jmp no puede reconocer cuál es el bit que quiero leer sin importar que coloque la Columna (l), l en el bucle for.
Re: Usar variable de bucle for en una fórmulaSería útil si pudiera adjuntar una tabla de datos de muestra.
Con su explicación adicional, intente cambiar
If( Right( :"x"n, Column(l) ) ) == "1"
a
If( Right( :"x"n, as Column( "Column" || char(l) )== "1"
Re: Usar variable de bucle for en una fórmulaHola Jim, aquí tienes la tabla de datos. Puse lo que espero ver en la tabla de datos. Los datos de la columna describen cuál es el valor "l" y de qué valor de "x" proviene
Re: Usar variable de bucle for en una fórmulaGracias Jim, creo que está funcionando, pero la impresión no coincidirá ligeramente. Funciona bien cuando se agrega ",1" detrás de "_l_" en la fórmula. Adjunté mi script jsl completo aquí
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
)
);
);Re: Usar variable de bucle for en una fórmulaTienes razón, ese es mi error.Corregiré mi entrada.
Re: Usar variable de bucle for en una fórmulaEl siguiente script parece funcionar.El script proporcionado utilizó \\ como iniciadores de comentarios, donde // es la sintaxis correcta.
La fórmula de trabajo real realmente se reducía al uso de la función Substr().
La adición de la sección Eval(Substitute(Expr())) simplemente cambió el valor de su variable l al valor real de l, en lugar de hacer referencia al valor a través de la variable.
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
)
);
);