Author |
Topic  |
|
stanlvw
Canada
Posts |
Posted - 01/17/2006 : 7:23:44 PM
|
Origin Version (Select Help-->About Origin): 7 Operating System: Windows XP
I have a slight problem in writing the code to get a popup window (or other methods) asking for the user for a max and min value for the range. I want make the values of columns 3 and 5 to be expressed as the distribution of column 6. Can anyone help me?
// Open Extract Worksheet window
menu -e 36496 // type in "abs(col(A)) <= c && abs(col(B)) <= c" for c comes from constraint calculations
// Add new columns; input 3 manually run.section(WKS,AddNewCol); wks.col6.type = 4; // set as x wks.col7.type = 1; // set as y wks.col8.type = 1; // set as y // Find number of rows
get col(3) -e npt;
// Get maximum and minimum values of the range
double min = get_var("min", &min); // <-- Problem double max = get_var("max", &max); //
// Divide the ranges to be in 11 cutoff values for determining 10 sections
double increment = (max-min)/10.0; for (ii=1; ii = 11; ii++) col(6)[ii] = min + increment*ii; col(6)[12] = max;
// Compare values of Fx and Fz to the array values and count frequency for (ii=1; ii = npt; ii++) { if (col(3)[ii] < min) col(7)[1] += 1; else if (col(3)[ii] < min+increment) col(7)[2] += 1; else if (col(3)[ii] < min+2*increment) col(7)[3] += 1; else if (col(3)[ii] < min+3*increment) col(7)[4] += 1; else if (col(3)[ii] < min+4*increment) col(7)[5] += 1; else if (col(3)[ii] < min+5*increment) col(7)[6] += 1; else if (col(3)[ii] < min+6*increment) col(7)[7] += 1; else if (col(3)[ii] < min+7*increment) col(7) += 1; else if (col(3)[ii] < min+8*increment) col(7)[9] += 1; else if (col(3)[ii] < min+9*increment) col(7)[10] += 1; else if (col(3)[ii] < max) col(7)[11] += 1; else col(7)[12] += 1;
if (col(5)[ii] < min) col(7)[1] += 1; else if (col(5)[ii] < min+increment) col(7)[2] += 1; else if (col(5)[ii] < min+2*increment) col(7)[3] += 1; else if (col(5)[ii] < min+3*increment) col(7)[4] += 1; else if (col(5)[ii] < min+4*increment) col(7)[5] += 1; else if (col(5)[ii] < min+5*increment) col(7)[6] += 1; else if (col(5)[ii] < min+6*increment) col(7)[7] += 1; else if (col(5)[ii] < min+7*increment) col(7) += 1; else if (col(5)[ii] < min+8*increment) col(7)[9] += 1; else if (col(5)[ii] < min+9*increment) col(7)[10] += 1; else if (col(5)[ii] < max) col(7)[11] += 1; else col(7)[12] += 1; }
Thanks,
Stanley
Edited by - stanlvw on 01/18/2006 12:47:24 PM |
|
Mike Buess
USA
3037 Posts |
Posted - 01/18/2006 : 09:19:08 AM
|
Hi Stanley,
1. get_var() is an Origin C function that is not recognized by LabTalk. (Actually, it's LT_get_var() and it does not bring up a popup window.) If you want a popup dialog for entering min and max you can do this...
//double min = get_var("min", &min); // <-- Problem (illegal LT command) //double max = get_var("max", &max); getn (min) min (max) max (Enter min and max);
2. If your Extract from Wks formula never changes you can bypass the first popup with this...
//menu -e 36496; wo -d; // duplicate wks for(i=wks.maxrows;i>0;i--) { if(abs(col(A)[i])<c && abs(col(B)[i])<c) { mark -d col(A) -b i -e i; // delete row i }; };
3. If you always add 3 columns you can bypass the 2nd popup with this...
//run.section(WKS,AddNewCol); wo -a 3; // add 3 columns
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 01/18/2006 09:48:18 AM |
 |
|
stanlvw
Canada
Posts |
Posted - 01/18/2006 : 12:46:42 PM
|
Hi Mike,
I have a question. See below.
quote:
Hi Stanley,
1. get_var() is an Origin C function that is not recognized by LabTalk. (Actually, it's LT_get_var() and it does not bring up a popup window.) If you want a popup dialog for entering min and max you can do this...
//double min = get_var("min", &min); // <-- Problem (illegal LT command) //double max = get_var("max", &max); getn (min) min (max) max (Enter min and max);
2. If your Extract from Wks formula never changes you can bypass the first popup with this...
What do you mean by Wks formula never changes?
quote:
//menu -e 36496; wo -d; // duplicate wks for(i=wks.maxrows;i>0;i--) { if(abs(col(A)[i])<c && abs(col(B)[i])<c) { mark -d col(A) -b i -e i; // delete row i }; };
3. If you always add 3 columns you can bypass the 2nd popup with this...
//run.section(WKS,AddNewCol); wo -a 3; // add 3 columns
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 01/18/2006 09:48:18 AM
|
 |
|
stanlvw
Canada
Posts |
Posted - 01/18/2006 : 1:19:52 PM
|
Here is my renewed code:
// Open Extract Worksheet window
menu -e 36496 // type in "abs(col(A)) <= c && abs(col(B)) <= c" for c comes from constraint calculations
// Add 4 new columns wo -a 4; // add 3 new columns wks.col6.type = 4; // set as x wks.col7.type = 1; // set as y wks.col8.type = 4; // set as x wks.col9.type = 1; // set as y // Find number of rows
get col(3) -e npt;
// Get maximum and minimum values of the range for both Fx and Fz
double Fxmin; double Fxmax; getn (Fxmin) Fxmin (Fxmax) Fxmax (Enter Fxmin and Fxmax);
double Fzmin; double Fzmax; getn (Fzmin) Fzmin (Fzmax) Fzmax (Enter Fzmin and Fzmax);
// Divide the ranges to be in 11 cutoff values for determining 10 sections
double Fxincrement = (Fxmax-Fxmin)/10.0; for (ii=1; ii = 11; ii++){ col(6)[ii] = Fxmin + Fxincrement*ii;}; col(6)[12] = Fxmax;
double Fzincrement = (Fzmax-Fzmin)/10.0; for (ii=1; ii = 11; ii++){ col(8)[ii] = Fzmin + Fzincrement*ii;}; col(8)[12] = Fzmax;
// Preset col(7) and col(9) values
col(7) = col(9) = {0};
// Compare values of Fx and Fz to the array values and count frequency for (ii=1; ii = npt; ii++) { if (col(3)[ii] < Fxmin) col(7)[1] += 1; else if (col(3)[ii] < Fxmin+Fxincrement) col(7)[2] += 1; else if (col(3)[ii] < Fxmin+2*Fxincrement) col(7)[3] += 1; else if (col(3)[ii] < Fxmin+3*Fxincrement) col(7)[4] += 1; else if (col(3)[ii] < Fxmin+4*Fxincrement) col(7)[5] += 1; else if (col(3)[ii] < Fxmin+5*Fxincrement) col(7)[6] += 1; else if (col(3)[ii] < Fxmin+6*Fxincrement) col(7)[7] += 1; else if (col(3)[ii] < Fxmin+7*Fxincrement) col(7) += 1; else if (col(3)[ii] < Fxmin+8*Fxincrement) col(7)[9] += 1; else if (col(3)[ii] < Fxmin+9*Fxincrement) col(7)[10] += 1; else if (col(3)[ii] < Fxmax) col(7)[11] += 1; else col(7)[12] += 1;
if (col(5)[ii] < Fzmin) col(9)[1] += 1; else if (col(5)[ii] < Fzmin+Fzincrement) col(9)[2] += 1; else if (col(5)[ii] < Fzmin+2*Fzincrement) col(9)[3] += 1; else if (col(5)[ii] < Fzmin+3*Fzincrement) col(9)[4] += 1; else if (col(5)[ii] < Fzmin+4*Fzincrement) col(9)[5] += 1; else if (col(5)[ii] < Fzmin+5*Fzincrement) col(9)[6] += 1; else if (col(5)[ii] < Fzmin+6*Fzincrement) col(9)[7] += 1; else if (col(5)[ii] < Fzmin+7*Fzincrement) col(9) += 1; else if (col(5)[ii] < Fzmin+8*Fzincrement) col(9)[9] += 1; else if (col(5)[ii] < Fzmin+9*Fzincrement) col(9)[10] += 1; else if (col(5)[ii] < Fzmax) col(9)[11] += 1; else col(9)[12] += 1; };
My problem now is col(6) to col(9) don't show anything. More correctly, col(7) and col(9) should be distributions according to col(6) and col(8). Is there something I could do? |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 01/18/2006 : 5:21:13 PM
|
quote: My problem now is col(6) to col(9) don't show anything.
LabTalk variables don't need to be declared and attempts to do so result in command errors that stop execution. Delete or comment out with // all lines that start with double.
quote: What do you mean by Wks formula never changes?
I meant if you always use the condition abs(col(A)) <= c && abs(col(B)) <= c then there is no point in using the Extract Worksheet Data dialog. The short script I gave you will accomplish the same thing.
...Rather, the following version of the script will do the same thing. It duplicates the active wks and deletes all rows that do not satisfy your condition.
wo -d; // duplicate wks for(i=wks.maxrows;i>0;i--) { if(abs(col(A)[i])<c || abs(col(B)[i])<c) { mark -d col(A) -b i -e i; // delete row i }; };
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 01/18/2006 5:41:51 PM |
 |
|
stanlvw
Canada
Posts |
Posted - 01/18/2006 : 5:49:46 PM
|
After getting rid of the doubles, my code looks like below:
// Open Extract Worksheet window
menu -e 36496 // type in "abs(col(A)) <= c && abs(col(B)) <= c" for c comes from constraint calculations
// Add 4 new columns wo -a 4; // add 3 new columns wks.col6.type = 4; // set as x wks.col7.type = 1; // set as y wks.col8.type = 4; // set as x wks.col9.type = 1; // set as y // Find number of rows
//get col(3) -e npt;
// Get maximum and minimum values of the range for both Fx and Fz
getn (Fxmin) Fxmin (Fxmax) Fxmax (Enter Fxmin and Fxmax);
getn (Fzmin) Fzmin (Fzmax) Fzmax (Enter Fzmin and Fzmax);
// Divide the ranges to be in 11 cutoff values for determining 10 sections
Fxincrement = (Fxmax-Fxmin)/10.0; for (ii=1; ii = 11; ii++){ col(6)[ii] = Fxmin + Fxincrement*ii;}; col(6)[12] = Fxmax;
Fzincrement = (Fzmax-Fzmin)/10.0; for (ii=1; ii = 11; ii++){ col(8)[ii] = Fzmin + Fzincrement*ii;}; col(8)[12] = Fzmax;
// Preset col(7) and col(9) values
col(7) = col(9) = {0};
// Compare values of Fx and Fz to the array values and count frequency for (ii=1; ii = wks.maxrows; ii++) { if (col(3)[ii] < Fxmin) col(7)[1] += 1; else if (col(3)[ii] < Fxmin+Fxincrement) col(7)[2] += 1; else if (col(3)[ii] < Fxmin+2*Fxincrement) col(7)[3] += 1; else if (col(3)[ii] < Fxmin+3*Fxincrement) col(7)[4] += 1; else if (col(3)[ii] < Fxmin+4*Fxincrement) col(7)[5] += 1; else if (col(3)[ii] < Fxmin+5*Fxincrement) col(7)[6] += 1; else if (col(3)[ii] < Fxmin+6*Fxincrement) col(7)[7] += 1; else if (col(3)[ii] < Fxmin+7*Fxincrement) col(7) += 1; else if (col(3)[ii] < Fxmin+8*Fxincrement) col(7)[9] += 1; else if (col(3)[ii] < Fxmin+9*Fxincrement) col(7)[10] += 1; else if (col(3)[ii] < Fxmax) col(7)[11] += 1; else col(7)[12] += 1;
if (col(5)[ii] < Fzmin) col(9)[1] += 1; else if (col(5)[ii] < Fzmin+Fzincrement) col(9)[2] += 1; else if (col(5)[ii] < Fzmin+2*Fzincrement) col(9)[3] += 1; else if (col(5)[ii] < Fzmin+3*Fzincrement) col(9)[4] += 1; else if (col(5)[ii] < Fzmin+4*Fzincrement) col(9)[5] += 1; else if (col(5)[ii] < Fzmin+5*Fzincrement) col(9)[6] += 1; else if (col(5)[ii] < Fzmin+6*Fzincrement) col(9)[7] += 1; else if (col(5)[ii] < Fzmin+7*Fzincrement) col(9) += 1; else if (col(5)[ii] < Fzmin+8*Fzincrement) col(9)[9] += 1; else if (col(5)[ii] < Fzmin+9*Fzincrement) col(9)[10] += 1; else if (col(5)[ii] < Fzmax) col(9)[11] += 1; else col(9)[12] += 1; };
My problem persists. Does it have something to do with variable declaration? But you just told me that variable declaration is automatic in LabTalk. |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 01/18/2006 : 9:42:10 PM
|
I see a few more errors...
1. The getn command appears twice. (Probably just a transcription error.)
2. Your for loops will never execute as written. Take, for example, the first loop...
for(ii=1; ii=11; ii++) { };
That says... start with ii=1 and increment by 1 as long as ii=11 (which is never true). I think you mean to increment by 1 as long as ii is less than or equal to 11...
for(ii=1; ii<=11; ii++) { };
3. col(7) = col(9) = {0}; is an illegal LabTalk statement. Try this instead...
col(7) = data(1,wks.maxrows); // give col(7) the correct number of values col(7) = 0; // set those values to zero col(9) = col(7); // copy col(7) to col(9);
...I think your last for loop will work after you change its conditions as discussed in the second point. However, here is a somewhat shorter version of that loop...
for (ii=1; ii <= wks.maxrows; ii++) { if(col(3)[ii]>=Fxmax) jj = 12; else { for(jj=1;jj<12;jj++) {if(col(3)[ii]<Fxmin+Fxincrement*(jj-1)) break;}; }; col(7)[jj] += 1; if(col(5)[ii]>=Fzmax) jj = 12; else { for(jj=1;jj<12;jj++) {if(col(5)[ii]<Fzmin+Fzincrement*(jj-1)) break;}; }; col(9)[jj] += 1; };
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 01/18/2006 9:43:32 PM
Edited by - Mike Buess on 01/19/2006 3:35:17 PM |
 |
|
Mike Buess
USA
3037 Posts |
Posted - 01/20/2006 : 10:14:12 AM
|
I see now that your getn commands are not identical so please disregard the first point in my previous post. It is also clear now that your for loops create bin boundaries for a histogram and fill their counts. LabTalk's data() and histogram() functions are much more efficient for that task...
menu -e 36496; // open Extract from Wks dialog wo -a 4; // add 4 new columns wks.col6.type = 4; // set as x wks.col7.type = 1; // set as y wks.col8.type = 4; // set as x wks.col9.type = 1; // set as y
// Get maximum and minimum values of the range for both Fx and Fz getn (Fxmin) Fxmin (Fxmax) Fxmax (Enter Fxmin and Fxmax); getn (Fzmin) Fzmin (Fzmax) Fzmax (Enter Fzmin and Fzmax);
// Create Fx histogram Fxincrement = (Fxmax-Fxmin)/10.0; Fxmin -= Fxincrement; // lower bin boundary for <Fxmin Fxmax += Fxincrement; // upper bin boundary for >=Fxmax col(6)=data(Fxmin,Fxmax,Fxincrement); // bin boundaries for Fx tmp=col(3)<Fxmin ? Fxmin : col(3); // create temporary dataset from col(3) and put all values <Fxmin in lowest bin tmp=tmp>=Fxmax ? Fxmax-Fxincrement/2 : tmp; // put all values >=Fxmax in highest bin col(7)=histogram(tmp,Fxincrement,Fxmin,Fxmax); // bin counts del tmp; // delete temporary dataset Fxmin += Fxincrement; // reset Fxmin to user's value Fxmax -= Fxincrement; // reset Fxmax to user's value
// Create Fz histogram Fzincrement = (Fzmax-Fzmin)/10.0; Fzmin -= Fzincrement; Fzmax += Fzincrement; col(8)=data(Fzmin,Fzmax,Fzincrement); // bin boundaries for Fz tmp=col(5)<Fzmin ? Fzmin : col(5); tmp=tmp>=Fzmax ? Fzmax-Fzincrement/2 : tmp; col(9)=histogram(tmp,Fzincrement,Fzmin,Fzmax); // bin counts del tmp; Fzmin += Fzincrement; Fzmax -= Fzincrement;
Mike Buess Origin WebRing Member |
 |
|
stanlvw
Canada
Posts |
Posted - 02/01/2006 : 6:44:29 PM
|
Mike,
I decided to use your worksheet extraction method because it's more user friendly. However, the loop doesn't delete the rows that doesn't satisfy the conditions. I need some help. Thanks
// Open Extract Worksheet window
getn (xmin) xmin (xmax) xmax (Enter min and max x coordinate of area patch to be analyzed); getn (ymin) ymin (ymax) ymax (Enter min and max y coordinate of area patch to be analyzed);
wo -d; // duplicate wks for(i=wks.maxrows;i>0;i--) { if( (col(A)[i] < xmin || col(A)[i] > xmax) || (col(B)[i] < ymin) || col(B)[i] > ymax) { mark -d col(A) -b i -e i; // delete row i }; };
Here
// Add 4 new columns wo -a 4; // add 4 new columns wks.col6.type = 4; // set as x wks.col7.type = 1; // set as y wks.col8.type = 4; // set as x wks.col9.type = 1; // set as y // Find number of rows
//get col(3) -e npt;
// Get maximum and minimum values of the range for both Fx and Fz
getn (Fxmin) Fxmin (Fxmax) Fxmax (Enter Fxmin and Fxmax);
getn (Fzmin) Fzmin (Fzmax) Fzmax (Enter Fzmin and Fzmax);
// Divide the ranges to be in 11 cutoff values for determining 10 sections
Fxincrement = (Fxmax-Fxmin)/10.0; for (ii=1; ii < 12; ii++){ col(6)[ii] = Fxmin + Fxincrement*(ii-1);}; col(6)[12] = Fxmax+1; // alert user that this range is above the maximum
Fzincrement = (Fzmax-Fzmin)/10.0; for (ii=1; ii < 12; ii++){ col(8)[ii] = Fzmin + Fzincrement*(ii-1);}; col(8)[12] = Fzmax+1; // alert user that this range is above the maximum
// Preset col(7) and col(9) values
col(7) = data(1,wks.maxrows); // give col(7) the correct number of values col(7) = 0; // set those values to zero col(9) = col(7); // copy col(7) to col(9);
// Compare values of Fx and Fz to the array values and count frequency for (ii=1; ii <= wks.maxrows; ii++) { if (col(3)[ii] < Fxmin) col(7)[1] += 1; else if (col(3)[ii] < Fxmin+Fxincrement) col(7)[2] += 1; else if (col(3)[ii] < Fxmin+2*Fxincrement) col(7)[3] += 1; else if (col(3)[ii] < Fxmin+3*Fxincrement) col(7)[4] += 1; else if (col(3)[ii] < Fxmin+4*Fxincrement) col(7)[5] += 1; else if (col(3)[ii] < Fxmin+5*Fxincrement) col(7)[6] += 1; else if (col(3)[ii] < Fxmin+6*Fxincrement) col(7)[7] += 1; else if (col(3)[ii] < Fxmin+7*Fxincrement) col(7) += 1; else if (col(3)[ii] < Fxmin+8*Fxincrement) col(7)[9] += 1; else if (col(3)[ii] < Fxmin+9*Fxincrement) col(7)[10] += 1; else if (col(3)[ii] < Fxmax) col(7)[11] += 1; else col(7)[12] += 1;
if (col(5)[ii] < Fzmin) col(9)[1] += 1; else if (col(5)[ii] < Fzmin+Fzincrement) col(9)[2] += 1; else if (col(5)[ii] < Fzmin+2*Fzincrement) col(9)[3] += 1; else if (col(5)[ii] < Fzmin+3*Fzincrement) col(9)[4] += 1; else if (col(5)[ii] < Fzmin+4*Fzincrement) col(9)[5] += 1; else if (col(5)[ii] < Fzmin+5*Fzincrement) col(9)[6] += 1; else if (col(5)[ii] < Fzmin+6*Fzincrement) col(9)[7] += 1; else if (col(5)[ii] < Fzmin+7*Fzincrement) col(9) += 1; else if (col(5)[ii] < Fzmin+8*Fzincrement) col(9)[9] += 1; else if (col(5)[ii] < Fzmin+9*Fzincrement) col(9)[10] += 1; else if (col(5)[ii] < Fzmax) col(9)[11] += 1; else col(9)[12] += 1; };
|
 |
|
Mike Buess
USA
3037 Posts |
Posted - 02/02/2006 : 08:35:39 AM
|
Does the script do the opposite of what it should? I think my latest suggestion had the conditions turned around and would delete the rows you wanted to keep. Perhaps this is what you want...
if(col(A)[i]>xmin || col(A)[i]<xmax || col(B)[i]>ymin || col(B)[i]<ymax) { mark -d col(A) -b i -e i; // delete row i };
...Since you are defining an area of the patch your conditions must be correct. (You want to keep xmin <= col(A) <= xmax.) I'm not sure why your script doesn't work but can suggest a method that is much faster than testing/deleting row-by-row...
getn (xmin) xmin (xmax) xmax (ymin) ymin (ymax) ymax (Enter min and max coordinates of area patch to be analyzed);
wo -d; // duplicate wks col(A)=tReplace(col(A),xmin,0/0,1); // replace col(A)<xmin with missing values (--) col(A)=tReplace(col(A),xmax,0/0,4); // replace col(A)>xmax with missing values sort -w %H col(A); // sort entire wks in ascending order wrt col(A). Missing values go to bottom. sum(col(A)); // sum.n = # rows - # missing values set %H -er sum.n; // remove all rows with missing values
// Repeat for col(B) col(B)=tReplace(col(B),ymin,0/0,1); col(B)=tReplace(col(B),ymax,0/0,4); sort -w %H col(B); sum(col(B)); set %H -er sum.n;
That will maintain row integrity but can scramble the row order. Row order probably doesn't matter in the rest of your script but you can use the sort object to restore the original row order as shown below if necessary. (Depending on the original row order it might be necessary to swap the primary and secondary sort orders, sort.cName1$ and sort.cName2$.)
// Return wks to original order sort.wksName$=%H; // sort active wks sort.c1=0; // sort all columns sort.r1=1; // start with row 1 sort.r2=wks.maxrows; // stop with last row sort.cName1$=A: A; // primary sort order... ascending wrt col(A) sort.cName2$=A: B; // secondary sort order... ascending wrt col(B) sort.wks(); // perform sort
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 02/02/2006 09:03:25 AM
Edited by - Mike Buess on 02/02/2006 11:10:00 AM |
 |
|
|
Topic  |
|