T O P I C R E V I E W |
senigalliese |
Posted - 11/03/2005 : 05:32:42 AM Origin Version (Select Help-->About Origin): 7.5 Operating System: XP
Dear members of the Forum,
I am a truly LabTalk beginner and the more I read the messages listed in the forum and the more I wonder which manual or user guide you use to know all the commands and the syntax you use in your messages, I have only the one that Origin provides on line but it is clearly not useful, bad structured and not sufficient for and advanced use of labtalk. I've been reading for hours the messages in this forum but I struggle to solve my problem as it is:
I work with hundreds of worksheets, each one has 58 columns, but I basically need to work only on three of them: x(7),y1(12),y2(17). I set y2=column 17 as categorical and its values are usual integers. I need to create a new worksheet from the original 58-column one where the columns are like xyzxyzxyzxyzxyzxyz etc etc,z= always categorical. Basically for each different value of the original column y2 I need three columns, and they have to stay sequentially in the same worksheet, in picture:
from X y1 y2(cat) 1 9 1 2 8 1 3 7 1 4 6 1 5 5 3 6 4 3 7 3 3 8 2 3 9 1 3 1 0 4 2 9 4 3 8 4 4 7 5 5 6 5
to X1 y1 z1(cat) X2 y2 z2(cat) X3 y3 z3(cat) X4 y4 z4(cat) 1 9 1 5 5 3 1 0 4 4 7 5 2 8 1 6 4 3 2 9 4 5 6 5 3 7 1 7 3 3 3 8 4 4 6 1 8 2 3 9 1 3
Once I have the new worksheet in this format I need to plot in the same window all these x1y1x2y2x3y3x4y4 datasets, with different colors and in different layers, but each X and Y axis in each layer has to be linked 1 to 1 to, let's say, layer 1. I spent a whole day trying to solve this problem on my own but I couldn't, I always get some error message. I do not even know if it is possible with labtalk to solve this problem, but if it was possible I would be 5 times faster at analyzing my data.
All the Best
|
19 L A T E S T R E P L I E S (Newest First) |
senigalliese |
Posted - 11/08/2005 : 12:50:14 PM Well, I do not know how to thank you Mike, very kind of you indeed. Now everything is working fine and I am able to deliver in 3 hours the amount of results usually obtained in one working day.
Thank you very much indeed. |
Mike Buess |
Posted - 11/06/2005 : 08:48:24 AM Still don't understand why you need each curve in a separate layer but here is the way to do it. To get the full legend in this case first select Format > Page, click the Legends tab and check the Include Data Plots from All Layers option. Then Graph > New Legend.
%W=%H; nz=wks.ncols/3; win -t P; loop (ii,1,nz) { jj=3*(ii-1); %W!wks.col$(jj+2).label$=%W!cell(1,jj+3)$; page.active=1; if( ii>1 ) { lay -n Both; layer$(ii).x.link=1; layer$(ii).y.link=1; layer$(ii).showx=0; layer$(ii).showy=0; }; layer -i200 %(%W,jj+2); set %(%W,jj+2) -c ii; // plot color limit %(%W,jj+2); if(ii==1 || xx1>limit.xmin) xx1=limit.xmin; if(ii==1 || xx2<limit.xmax) xx2=limit.xmax; if(ii==1 || yy1>limit.ymin) yy1=limit.ymin; if(ii==1 || yy2<limit.ymax) yy2=limit.ymax; }; page.active=1; x1=xx1; x2=xx2; y1=yy1; y2=yy2; del -v xx*; del -v yy*;
Mike Buess Origin WebRing Member |
senigalliese |
Posted - 11/06/2005 : 08:33:49 AM Thanks Mike for the plotting script, it works, although what I am trying to do is to plot every Y? column in a different layer; let's say, if I have 7 possible different values of coly2 I will have 21 columns in the resulting worksheet you finally managed to obtain with your script (which is working fine, tested again in several worksheets), then I will need 7 layers in the same plot window, each corresponding to it's Y column. Moreover, I need all the layers to have the X and Y axes linked to the layer #1 (whatever the Y column/coly2 value refers to) straight 1 to 1, as you can choose under the Origin Layer Properties menu. I am working on it now, but I find the on line LabTalk guide very unuseful! |
Mike Buess |
Posted - 11/05/2005 : 2:19:17 PM Glad the script is finally working. Now I'll give you something to think about when you wake up. The next script plots each Y column in your sorted wks as a separate line in the same layer. (Use layer -i201 or layer -i202 for scatter or line+symbol plots, respectively.) Note that each Y column is plotted against the X column on its left (Y1 vs X1, Y2 vs X2, etc.) so the plots are automatically scaled correctly. Is this the sort of graph you're after? Same can be done in multiple layers but this is much easier.
%W=%H; // save wks name nz=wks.ncols/3; // number of Y columns win -t P; // open graph window loop (ii,1,nz) { jj=3*(ii-1); %A=%W!cell(1,jj+3)$; // get value in Z column %W!wks.col$(jj+2).label$=%A; // label the Y column layer -i200 %(%W,jj+2); // add Y as line plot }; layer -g; // group all plots layer -a; // rescale to show all data legend; // draw legend
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 11/05/2005 2:25:39 PM |
senigalliese |
Posted - 11/05/2005 : 1:11:40 PM Thanks Mike!...i tested the routine in many different worksheets now, it is working fine....thank you very much indeed. I'll go to bed now, here is almost daylight now. Once up again I'll focus on the plotting then. Thanks again Mike, have a nice day... |
Mike Buess |
Posted - 11/05/2005 : 1:02:33 PM Sorry you can't get it to work. With the latest change the script extracts all rows from each y2 category of my test wks. I have fewer rows per category than you do but each category contains over 30 rows, which is the relevant number. I don't know what to suggest without seeing your data.
Mike Buess Origin WebRing Member |
senigalliese |
Posted - 11/05/2005 : 12:38:10 PM I'm sorry Mike,
there must be something weird here, this 30-rows limit seems to be worksheet dependent, moreover, sometimes I have this problem with the same worksheet indeed, I mean, for some values of coly2 the limit of 30 rows manifests itself, for other it doesn't although I have thousand rows for each coly2 value, not 30. It's very unfortunate, I'm giving up, I do not see the solution to this problem |
Mike Buess |
Posted - 11/05/2005 : 12:01:10 PM That did not happen in my tests. All relevant rows (even >30) were copied for each y2 value. Perhaps you made a mistake copying/pasting my script.
...Sorry, now I see that if the number of rows for subsequent y2 values is greater than 30 but less than the previous maximum rows then only 30 values are copied. Change the line if(i3>wks.nrows) set %H -er i3; to this...
if(i3>30) { if(i3>wks.nrows) set %H -er i3; else set %H -er wks.nrows; };
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 11/05/2005 12:15:03 PM |
senigalliese |
Posted - 11/05/2005 : 11:56:27 AM Dear Mike,
the new routine corrected the problem of the bad copied values of coly2 and the 30 rows limit for the first dataset related to the first value of coly2, but unfortunately only 30 rows from the mother worksheet are copied for colx,coly1 and coly2 related in order to the second, third etc etc coly2 different values.I'm working on it but I can't solve the problem yet. |
Mike Buess |
Posted - 11/05/2005 : 08:53:38 AM OK, I duplicated enough rows of your sample data to reproduce your problem. Turns out the solution is a little more complicated than I first imagined. Coly2 was not properly copied because it was categorical so now I delay resetting it to categorical until the end...
colx=7; // x column no. coly1=12; // y1 column no. coly2=17; // y2 column no. nrows=wks.maxrows; // no. of rows set %(%H,coly2) -dc 0; // set y2 non-categorical tmp=diff(%(%H,coly2)); // differences of y2 values tmp=tmp?1:0; // set nonzero differences to 1 sum(tmp); nz=1+sum.total; // no. of categories %W=%H; // save wks name win -t D; // create new wks del col(1); // remove columns del col(1); i2=0; loop (ii,1,nz) { i1=i2+1; i2=list(1,tmp); // find first 1 in tmp if(i2==0) i2=nrows; else tmp[i2]=0; i3=i2-i1+1; // no. of rows in category wks.addCol(); // add Y column wks.col$(wks.ncols).type=4; // make it X; wks.addCol(); // add Y column; wks.addCol(); // add Y column wks.col$(wks.ncols).type=6; // make it Z if(i3>wks.nrows) set %H -er i3; copy -b i1 %(%W,colx) %(%H,wks.ncols-2) -b 1 -e i3; copy -b i1 %(%W,coly1) %(%H,wks.ncols-1) -b 1 -e i3; copy -b i1 %(%W,coly2) %(%H,wks.ncols) -b 1 -e i3; set %(%H,wks.ncols) -dc 1; // set categorical; }; set %(%W,coly2) -dc 1; // set y2 categorical del tmp;
Mike Buess Origin WebRing Member |
senigalliese |
Posted - 11/05/2005 : 08:25:38 AM Hi Mike,
I'm saying the script copies all the rows of colx related to ONLY the first value of coly2 (in total 250 values), then only the first 30 values for coly1 and coly2. Moreover, the values in the copied coly2 are rubbish, are not the original ones. Very strange, maybe the copy command is not that reliable!
Thanks Mike |
Mike Buess |
Posted - 11/05/2005 : 08:13:08 AM quote: Your command definitely helps, unfortunately I do not know why the routine keeps on copying only the first 30 rows of coly1 for each coly2 value, although column tmp is fine
Are you saying the script copies all rows of colx but only 30 rows of coly1 and coly2?
Mike Buess Origin WebRing Member |
senigalliese |
Posted - 11/05/2005 : 07:47:59 AM Your command definitely helps, unfortunately I do not know why the routine keeps on copying only the first 30 rows of coly1 for each coly2 value, although column tmp is fine!
Thanks again Mike, very kind of you.
PS: For what concerns the plotting: let's think I have only 7 different possible values for coly2, then in the end I will have 7 data sets. I need to plot them all together in the same plot, and till here I can work it out, but I need any data set in a different layer, and each layer linked 1:1 to the first one, whatever it is, in order to have the same x and y axis for each dataset and not to mess up the plot! |
Mike Buess |
Posted - 11/04/2005 : 4:58:12 PM Probably because a new wks has only 30 rows by default. Insert this before the first copy command...
if(i3>wks.nrows) set %H -er i3;
Mike Buess Origin WebRing Member |
senigalliese |
Posted - 11/04/2005 : 11:58:03 AM The Syntax of your routine is fine, but I do not know why, the copy command copies only the first 30 rows of any column, i tested it using even random columns and worksheets, just to try the command itself, and keeps copying only from 1 to max 30 rows!
regards |
senigalliese |
Posted - 11/04/2005 : 11:12:16 AM Thank you very much Mike. You routine is good but still not perfect. the problem is that it does not take all the values from the original worksheet. I've spent one hour now trying to understand what goes wrong but still I have not found it. Why the columns in the "results" worksheet are truncated?
Cheers
|
Mike Buess |
Posted - 11/03/2005 : 11:09:15 AM It might be useful to post your script.
...Following script sorts your example data properly. We can worry about plotting them later since I don't entirely understand how you want to do it. I'm not convinced that you need categorical columns either but have used categorical where you wanted.
colx=7; // x column no. coly1=12; // y1 column no. coly2=17; // y2 column no. nrows=wks.maxrows; // no. of rows set %(%H,coly2) -dc 0; // set y2 non-categorical tmp=diff(%(%H,coly2)); // differences of y2 values set %(%W,coly2) -dc 1; // set y2 categorical tmp=tmp?1:0; // set nonzero differences to 1 sum(tmp); nz=1+sum.total; // no. of categories %W=%H; // save wks name win -t D; // create new wks del col(1); // remove columns del col(1); i2=0; loop (ii,1,nz) { i1=i2+1; i2=list(1,tmp); // find first 1 in tmp if(i2==0) i2=nrows; else tmp[i2]=0; i3=i2-i1+1; // no. of rows in category wks.addCol(); // add Y column wks.col$(wks.ncols).type=4; // make it X copy -b i1 %(%W,colx) %(%H,wks.ncols) -b 1 -e i3; wks.addCol(); // add Y column copy -b i1 %(%W,coly1) %(%H,wks.ncols) -b 1 -e i3; wks.addCol(); // add Y column wks.col$(wks.ncols).type=6; // make it Z set %(%H,wks.ncols) -dc 1; // set categorical copy -b i1 %(%W,coly2) %(%H,wks.ncols) -b 1 -e i3; }; del tmp;
Mike Buess Origin WebRing Member
Edited by - Mike Buess on 11/03/2005 12:24:27 PM
Edited by - Mike Buess on 11/03/2005 12:33:49 PM |
senigalliese |
Posted - 11/03/2005 : 10:44:57 AM Dear Mr Buess,
I've just tried setting the column as non-categorical, but I am afraid the problem is not that; as a matter of fact I keep on reading error messages from the script window I do not even know the meaning of. Thank you very much anyway for replying my topic.
Regards |
Mike Buess |
Posted - 11/03/2005 : 09:11:10 AM If you are creating columns in the new wks based on the numeric values of column 17 in the old wks your script probably fails because numeric tests do not work on categorical columns. Try setting column 17 as non-categorical before you run your script.
Mike Buess Origin WebRing Member |
|
|