Author |
Topic |
|
lillt91
Germany
14 Posts |
Posted - 02/19/2018 : 06:55:20 AM
|
Origin Ver. and Service Release (Select Help-->About Origin): Operating System:
Hi, I want to copy the value of column(2), which gets the closest to the value 1050 to a new column. An approach to solve my problem is my script below. But sometimes the script is not precise enough. I.e. when there are two values which satisfy my conditions. Then my script will always pick the 2nd value, because of the loop. Is there any chance to compare values to a set value (1050 in this example) and pick the one with the lowest deviation?
loop(row, 20, 90) { vgl1=wcol(2)[row]/1050; if(vgl1>0.99 && vgl1<1.01) { wcol(3)[1]=wcol(1)[row]; wcol(4)[1]=wcol(2)[row]; } } |
Edited by - lillt91 on 02/20/2018 10:24:29 AM |
|
Hideo Fujii
USA
1582 Posts |
Posted - 02/19/2018 : 10:46:30 AM
|
Hi lillt91,
Could you please try the following snippet?//////////////////////////////////////
iBegin=20; //Begining of row range
iEnd=90; //End of row range
range rr=col(B)[iBegin:iEnd]; //Range as a temp dataset
sum(abs(rr-1050)); //Get stats
wcol(3)[1]=wcol(1)[sum.imin+iBegin-1]; //Original x of min
wcol(4)[1]=wcol(2)[sum.imin+iBegin-1]; //Original y of min
////////////////////////////////////// Hope this works.
--Hideo Fujii OriginLab |
Edited by - Hideo Fujii on 02/19/2018 10:52:43 AM |
|
|
arstern
USA
237 Posts |
|
lillt91
Germany
14 Posts |
Posted - 02/20/2018 : 07:38:58 AM
|
Thank you for your answers! Both work fine but I am struggling with putting those solutions into a loop like this:
loop(ii, 1, 225) { cc=ii*4; loop(row, 20, 90) { vgl1=wcol(cc+2)[row]/1050; if(vgl1>0.99 && vgl1<1.01) { wcol(cc+3)[1]=wcol(1)[row]; wcol(cc+4)[1]=wcol(cc+2)[row]; }
vgl2=wcol(cc+2)[row]/1150; if(vgl2>0.99 && vgl2<1.01) { wcol(cc+3)[2]=wcol(1)[row]; wcol(cc+4)[2]=wcol(cc+2)[row]; } } }
edit: this is my not satisfying solution: quote: loop(ii, 1, 56) { cc=ii*4;
loop(row, 20, 90) //Linke Seite der Temperaturkurve { vgl1=wcol(cc+2)[row-1]-1050; vgl2=sqrt(vgl1*vgl1);
vgl3=wcol(cc+2)[row]-1050; vgl4=sqrt(vgl3*vgl3);
vglx=wcol(cc+2)[row]/1050;
if(vgl4 < vgl2 && vglx>0.99 && vglx<1.01){min1=row;}
vgl5=wcol(cc+2)[row-1]-1150; vgl6=sqrt(vgl5*vgl5);
vgl7=wcol(cc+2)[row]-1150; vgl8=sqrt(vgl7*vgl7);
vgly=wcol(cc+2)[row]/1150;
if(vgl8 < vgl6 && vgly>0.99 && vgly<1.01){min2=row;} }
wcol(cc+3)[1]=col(1)[min1]; wcol(cc+4)[1]=wcol(cc+2)[min1]; wcol(cc+3)[2]=col(1)[min2]; wcol(cc+4)[2]=wcol(cc+2)[min2]; }
|
Edited by - lillt91 on 02/20/2018 10:24:45 AM |
|
|
arstern
USA
237 Posts |
Posted - 02/20/2018 : 1:58:36 PM
|
Hi,
for(ii=1; ii<=255; ii++) { int ind = Index(1050, col($(ii)));
n=wks.ncols+1;
col($(n))[1]=col($(ii))[ind]; }
You can use this script if you want to find the value to the nearest 1050 for every column in the worksheet. It isn't exactly clear to me if you want to find for every column or for specific columns?
-Aviel |
|
|
lillt91
Germany
14 Posts |
Posted - 02/21/2018 : 03:31:59 AM
|
So this is my worksheet. Col(1) is the main X-Axis with the time data I need. Col(2),Col(6), Col(10)... are my temperature columns.
I want the programm to find the closest value to 1050 for every column with temperature data from row 20 to 90 and from row 64 to 134 and give it out to column ii(+2). column ii(+1) should have the value of col(1) in the same row.
Edit: I found a solution which works fine for me:
quote: //X-Werte und so weiter vglm1=200; vglm2=200; vglm3=200; vglm4=200;
loop(ii, 1, 56) { cc=ii*4-2;
limit wcol(cc); //Maximum jeder Spalte ausgeben lassen bb=limit.imax; wcol(cc+1)[3] = wcol(1)[bb]; wcol(cc+2)[3] = limit.ymax;
loop(row, 20, bb) //Linke Seite der Temperaturkurve { vgl1=abs(col($(cc))[row]-1050); if(vgl1 < vglm1) { vglm1=vgl1; min1=row; }
vgl2=abs(col($(cc))[row]-1150); if(vgl2 < vglm2) { vglm2=vgl2; min2=row; } } wcol(cc+1)[1]=col(1)[min1]; wcol(cc+2)[1]=wcol(cc)[min1]; wcol(cc+1)[2]=col(1)[min2]; wcol(cc+2)[2]=wcol(cc)[min2];
loop(row, bb, 134) //Rechte Seite der Temperaturkurve { vgl3=abs(col($(cc))[row]-1150); if(vgl3 < vglm3) { vglm3=vgl3; min3=row; }
vgl4=abs(col($(cc))[row]-1050); if(vgl4 < vglm4) { vglm4=vgl4; min4=row; } } wcol(cc+1)[4]=col(1)[min3]; wcol(cc+2)[4]=wcol(cc)[min3]; wcol(cc+1)[5]=col(1)[min4]; wcol(cc+2)[5]=wcol(cc)[min4];
}
|
Edited by - lillt91 on 02/21/2018 11:11:47 AM |
|
|
|
Topic |
|
|
|