How to get multiple interpolated Y values from many X’s

posted in: Data Analysis | 2

DOC-2334_MultiInterpHave you ever wanted to bunch up all Y values corresponding to multiple X values from multiple datasets (plots) at one time using interpolation (or extrapolation) technique like in the following sample graph? One way to achieve such task is to apply the “Vertical Cursor” gadget multiple times as discussed in the forum post, http://www.originlab.com/forum/topic.asp?TOPIC_ID=20330 .

Although this is a handy interactive tool, if you have many specific X values to interpolate, you can try the following methods of interpolation applied on the worksheet data.

CASE-1: Using the “Interpolate/Extrapolate” menu

This method is only applicable when your desired X positions are equally spaced in a range. You can run this from “Analysis> Mathematics> Interpolate/Extrapolate” menu, then you enter the X Minimum and Maximum, as well as the Number of Points (after turning OFF the Auto check boxes). For example, you can enter: X Minimum=0, X Maximum=10, and Number of Points=11 , to produce Y values at 0, 1, 2, … , 10.

 

CASE-2: Using the “Interpolate/Extrapolate Y from X” menu

This method is useful when the number of source datasets are not many, but they may exist in various workbooks or worksheets. As a preparation of the procedure, first make a worksheet which has a column containing your desired X values to interpolate. For example, in the screenshot below, a new sheet “Results” is created, and you enter the X values to interpolate into the first column, A(X). (You only need this X column at this moment, so you may delete the empty B(Y).)

Now you can run the interpolation by “Analysis> Mathematics> Interpolate/Extrapolate Y from X” menu for each of your source Y dataset. You can specify the column for “X Values to Interpolate”. Note that the column part of the “Result of interpolation” has been set to “<New>” in the specific worksheet ([Book1]Results in this sample) so that every time you run this menu command, the interpolated result is automatically added as a new column in the Results worksheet. Also, the recalculation mode is set to Auto so that it recalculates automatically when the X values to interpolate in Results worksheet are updated.  Repeat this step for all Y datasets.

scr_Interp-01a

 

CASE-3: Using a Script

If you have lots of source Y datasets to be interpolated, the method in CASE-2 takes tedious steps to interpolate all Y datasets. But, if your source datasets are arranged in a single worksheet with a regular pattern of designations like XYY…Y or XYXY…XY, you can accomplish all tasks in a single step with a help of simple script. For example, the following sample worksheet contains ten(10) Y datasets, and the X values to interpolate are stored in the first column in the second sheet(=Sheet2):

scr_Interp-02a

Try to run the following simple script (using “interp1” x-function).:

You get the whole result in a single run!

2 Responses

  1. purpleblitz

    Hi, please could you give more detail on how the script is written and executed? Thanks! 🙂

    • Hideo Fujii

      Hi purpleblitz,
      You can copy-and-paste the script code in this article into the Script window (“Window: Script Window” menu to open), highlighted all pasted lines, then press ENTER key to run the block of lines. Also, you can save this code in a script file (a text file which has .OGS extension), and later run it by “run.section” command. Please refer to the following explanation:
      http://www.originlab.com/doc/LabTalk/guide/Running-Scripts
      Hope this helps.
      –Hideo Fujii, Originlab

Leave a Reply