Data_table

 

Description

Table lookup with interpolation.

Syntax

double Data_table( double dX, Dataset * pdsYdata, Dataset * pdsXdata = NULL )

Parameters

dX
[input] The index value used to perform the lookup
pdsYdata
[input] The Y dataset, or the row number data set
pdsXdata
[input] The X dataset, or the Y dataset when row numbers are specified in the second parameter.

Return

Returns the interpolated lookup value from two sets of monotonic data.

Examples

EX1

// This is a self contained sample program for the function Data_table, 
// Its sample data is created at the beginning of the program. 
// To run the program, enter the following command in the Script window:
//   Data_table_ex1
// It returns like the following three lines:
//   1) Find Index=2.5 => B(Y)=100
//   2) Find A(X)=3.0 => B(Y)=100
//   3) Find B(Y)=100.0 => Row#(C)=2.5
//
void Data_table_ex1()
{
    double Xval, Yval, RowNumber;
    Worksheet wks;
    wks.Create();
    wks.AddCol(); 
    Dataset myXDs(wks,0);
    Dataset myYDs(wks,1);
    Dataset dsRowNums(wks,2);
    
    //******* Create sample data *****************
    myXDs.SetSize(3);
    myYDs.SetSize(3);
    dsRowNums.SetSize(3);
    myXDs[0]=1;  myYDs[0]=10;  dsRowNums[0]=1; 
    myXDs[1]=2;  myYDs[1]=40;  dsRowNums[1]=2; 
    myXDs[2]=4;  myYDs[2]=160; dsRowNums[2]=3;
    //******** End of Sample Data Creation *******    

// Demonstration 1: 
// To find Y value at given row number, pass desired row number in place of X value and 
// specify NULL for X data set (Data_table will interpolate for fractional row numbers)
    Yval=Data_table(2.5,&myYDs,NULL);
    printf("1) Find Index=2.5 => B(Y)=%g\n",Yval); // Demonstration of Data_table

// Demonstration 2:
// To find Y value at given X value, pass X value and specify X data set 
// (Data_table will interpolate for all X values)
    Yval=Data_table(3.0, &myYDs, &myXDs);
    printf("2) Find A(X)=3.0 => B(Y)=%g\n",Yval); // Demonstration of Data_table

// Demonstration 3:
// To find row number of given Y value, pass Y value in place of X value, 
// specify Y data set as X data set, and pass a data set containing row numbers 
// {1,2,3,4...} for Y data set (Data_table will interpolate to fractional row numbers)
    RowNumber=Data_table(100.0, &dsRowNums, &myYDs);
    printf("3) Find B(Y)=100.0 => Row#(C)=%g\n",RowNumber); // Demonstration of Data_table
}

Remark

Table lookup with interpolation from two data sets (X and Y) of monotonic data. To find the y value at a given row number pass the Y data set but pass NULL for the X data set. To find the y value at a given x value pass the Y data set and the X data set. To find the row number of a given y value pass a data set containing row numbers as the Y data set and pass the Y data set as the X data set.

Function Data_list provides table lookup without interpolation.

See Also

Header to Include

origin.h

Reference