The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 why won't this work
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

rtsen

Canada
5 Posts

Posted - 04/29/2003 :  3:34:55 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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.

Laurie

USA
404 Posts

Posted - 05/02/2003 :  10:56:37 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000