2.1.17.8.21.2 Data_list
Description
Find first occurrence of value in data set.
Syntax
int Data_list( double dX, Dataset * pdsData, int nPrecision = 8 )
Parameters
- dX
- [input] Value to lookup
- pdsData
- [input] Dataset to look in for value
- nPrecision
- [input] Indicates precision to use when determining if the given x value matches a value in the data set. Pass -1 to use Origin's default internal double comparison precision as specified by the @ND system variable. Otherwise, pass a positive integer to specify precision (significant digits). When either the x or the data set value is non-zero, the following condition indicates whether or not a match has been found: abs((v2-v1)/(abs(v1)+abs(v2))) < 10^(-nPrecision).
Return
Returns the row index of the first occurence of a given value found in a data set. Returns -1 if value is not found.
Examples
EX1
// This is a self contained sample program for the function Data_list,
// Its sample data is created at the beginning of the program.
// To run the program, enter the following command in the Script window:
// Data_list_ex1
// It returns like the following three lines:
// 1) Find A(X)=2.04 => FOUND: Index=2 Val=2 Tolerance:0.00990099 < Precision:10^2
// 2) Find A(X)=2.05 => NOT FOUND with Tolerance < Precision:10^2
// 3) Find A(X)=2.00000000000001e+000 => FOUND: Index=2 Val=2 Tolerance=2.55351e-015 < Precision(@ND)=1e-014
//
void Data_list_ex1()
{
double tol, v1, v2, ND;
int nrow;
Worksheet wks;
wks.Create();
Dataset myDs(wks,0);
//******* Create sample data *****************
myDs.SetSize(4);
myDs[0]=1;
myDs[1]=2;
myDs[2]=3;
myDs[3]=4;
//******** End of Sample Data Creation *******
// Demonstration 1:
// Successful case to find a value which tolerance is smaller than the precision value.
nrow=Data_list(2.04, &myDs, 2); // tolerance is < 10^-2 , and this suceeds.
if(nrow == -1)
printf("1) Find A(X)=2.04 => NOT FOUND with Tolerance < Precision:10^2\n");
else {
tol = fabs(myDs[nrow]-2.04)/(2.04+fabs(myDs[nrow]));
printf("1) Find A(X)=2.04 => FOUND: Index=%d Val=%g Tolerance:%g < Precision:10^2\n",nrow+1,myDs[nrow],tol );
}
// Demonstration 2:
// Failing case to find a value which tolerance is larger than the precision value.
nrow=Data_list(2.05, &myDs, 2); // tolerance is < 10^-2 , and this fails.
if(nrow == -1)
printf("2) Find A(X)=2.05 => NOT FOUND with Tolerance < Precision:10^2\n");
else {
tol = fabs(myDs[nrow]-2.04)/(2.04+fabs(myDs[nrow]));
printf("2) Find A(X)=2.05 => FOUND: Index=%d Val=%g Tolerance:%g < Precision:10^2\n",nrow+1,myDs[nrow],tol );
}
// Demonstration 3:
// To find a value with the precision value specified by @ND system variable.
LT_get_var("@ND", &ND); // to get the value of @ND system variable
v1=2.00000000000001;
nrow=Data_list(v1, &myDs, -1); // tolerance is compared to the value of @ND as the precision.
if(nrow == -1)
printf("3) Find A(X)=%g => NOT FOUND with Tolerance < Precision:val(@ND):%g\n",v1,ND);
else {
tol = fabs(myDs[nrow]-v1)/(fabs(v1)+fabs(myDs[nrow]));
printf("3) Find A(X)=%.14e => FOUND: Index=%d Val=%g Tolerance=%g < Precision(@ND)=%g\n",v1,nrow+1,myDs[nrow],tol,ND);
}
}
Remark
Search for the first occurrence of a given value in a data set.
See Also
Header to Include
origin.h
Reference
|