T O P I C R E V I E W |
rtsen |
Posted - 04/29/2003 : 3:34:55 PM Hi, i'm confused why the following code doesn't do what I expect.
Here is some background info. I have three columns, 1 X column (time) and 2 Y columns (temp1, temp2). I am using the LabTalk function peaks to determine where the peaks are in temp1, then using the index where the peaks are to get a subset of temp1 and temp 2. This is my code:
if("%C" != "") { %N = %C; %M = %H; win -a %[%N,'_']; limit(%N); rows = LIMIT.SIZE; ph = .4*(LIMIT.YMAX - LIMIT.YMIN); pw = int(.02 * rows); getnum (Width/2) pw (Height Difference) ph (Peak Analysis Parameters); wo -a 4; %A=Peaks %[%C,>'_']; %Q=Index %[%C,>'_']; %Z=%M_temp2; wks.col$(wks.ncols-1).name$ = %A; wks.col$(wks.ncols - 2).name$ = %Q; wks.col$(wks.ncols - 3).type = 5; %O = %(%H,$(wks.ncols-3)); wcol(wks.ncols-2) = peaks(%N,pw,ph); get wcol(wks.ncols-2) -e numpeaks; for(ii = 1; ii <= numpeaks; ii++) { nn = wcol(wks.ncols-2)[ii]; wcol(wks.ncols-3)[nn] $= Peak$(ii); wcol(wks.ncols-1)[ii] = %N(nn); wcol(wks.ncols)[ii] = %Z(nn); } win -a %M; if(exist(%M)==3) layer -i %O; } else { type -b Select a column or plot your data.; }
I get the right subset for temp1 but temp2 is wrong, I usually get that subset temp2 is one number. Initially I thought I did something wrong with "%Z", so I substituted the column name instead of using "%Z" but I still get the same result.
Please tell me where I went wrong, thanks in advance. |
1 L A T E S T R E P L I E S (Newest First) |
Laurie |
Posted - 05/02/2003 : 10:56:37 AM The following lines need to be modified:
wcol(wks.ncols-1)[ii] = %N(nn); wcol(wks.ncols)[ii] = %Z(nn);
to the following:
wcol(wks.ncols-1)[ii] = %N[nn]; //note the square brackets wcol(wks.ncols)[ii] = %Z[nn];
The parantheses mean something entirely different from the square brackets. When you use parantheses, you are using the dataset as a function where the 'nn' argument is now considered an X value that is being passed to the function. The function then returns the corresponding Y value for that given X value.
When you use square brackets then the 'nn' is an index, and the return value is the value in that dataset at that given index or row number.
Also the following line, should be modified: wcol(wks.ncols-3)[nn] $= Peak$(ii);
to the following: wcol(wks.ncols-3)[ii] $= Peak$(ii);
This is because you want the Peak1 text to appear in the first row of the dataset and not in the row corresponding to the index value of the first peak.
OriginLab Technical Support |
|
|