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
 Origin Forum
 Extract data
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

gulitog1

6 Posts

Posted - 09/16/2012 :  12:17:56 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
If I have two colums of data X and Y, and I want to extract the cell Y corresponding to a particular value of X, that is closest one to my target (for example,the closest value to X=1, which script can I use?

Hideo Fujii

USA
1582 Posts

Posted - 09/17/2012 :  1:52:39 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi gulitog1A

The following sample may serve your purpose:
////////////////////////////////////
function double difv(double v1, double v2) {
  return abs(v1-v2);
}
target=1;
minv=1e307;
Loop(ii,1,wks.maxRows) {
  d=difv(col(1)[ii], target);
  if(d<minv) { minv=d; mini=ii; }
}
//// Output results /////
worksheet -a 3;
nc=wks.ncols;
wcol(nc-2)[C]$=Index;  wcol(nc-2)[1]=mini;
wcol(nc-1)[C]$=X;      wcol(nc-1)[1]=col(1)[$(mini)];
wcol(nc)[C]$=Y;        wcol(nc)[1]=col(2)[$(mini)];
////////////////////////////////////

Hope this helps.

--Hideo Fujii
OriginLab

Edited by - Hideo Fujii on 09/17/2012 2:21:47 PM
Go to Top of Page

greg

USA
1378 Posts

Posted - 09/17/2012 :  3:11:32 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Rather than the closest value, how about interpolating to get the estimated Y value at an exact X value?

range rax = [Book1]Sheet1!col(1);
range ray = [Book1]Sheet1!col(2);
range raxy = (rax,ray);
InterpolatedY = raxy(1);
Go to Top of Page

gulitog1

6 Posts

Posted - 09/18/2012 :  3:00:02 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by greg

Rather than the closest value, how about interpolating to get the estimated Y value at an exact X value?

range rax = [Book1]Sheet1!col(1);
range ray = [Book1]Sheet1!col(2);
range raxy = (rax,ray);
InterpolatedY = raxy(1);



Thank your for your reeply. After that do I need to insert a command like col(3)=InterpolatedY, because it does not seem to work. And the one afetr raxy, is it the target?
Go to Top of Page

greg

USA
1378 Posts

Posted - 09/19/2012 :  4:20:07 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
range raxy = (rax,ray) creates an XYRange out of rax (column 1) and ray (column 2) where rax is the 'x' and ray is the 'y'. I could interpolate the other way by using range rayx = (ray,rax).

InterpolatedY = raxy(1) finds the value of Y at X = 1 in the XYRange.

InterpolatedY is a scalar value, so:
col(3)=InterpolatedY
will not do anything unless you have set a data range for column 3. You could set a cell in column 3 with:
col(3)[1] = InterpolatedY
Go to Top of Page

gulitog1

6 Posts

Posted - 09/22/2012 :  10:53:38 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by greg

range raxy = (rax,ray) creates an XYRange out of rax (column 1) and ray (column 2) where rax is the 'x' and ray is the 'y'. I could interpolate the other way by using range rayx = (ray,rax).

InterpolatedY = raxy(1) finds the value of Y at X = 1 in the XYRange.

InterpolatedY is a scalar value, so:
col(3)=InterpolatedY
will not do anything unless you have set a data range for column 3. You could set a cell in column 3 with:
col(3)[1] = InterpolatedY


Thank you. But I don't have X=1, I have, for example,: X=0.9997,1,005,... How can I modify the script?
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