#include "mex.h" /* Returns the interpolated output value at index, i.e. (index, value) * using the known (inp, outp) pairs. */ void table1(double *inp, double *outp, int length, double index, int output_length, double *value_return, int stride) { int i,j; double k; /* find the first element of inp greater than index */ #if 1 for(i=0;i index) break; } #else /* binary search */ int low = 0, high = length; while(low < high) { i = (high+low)/2; if(inp[i] >= index) high = i; else if(inp[i] < index) low = i+1; } #endif /* too small or large? guess the extreme value */ if(i == 0) { k = 1; for(j=0;j 1)) mexErrMsgTxt("Usage: y = table1(tab, x)"); pr = mxGetPr(prhs[0]); length = mxGetM(prhs[0]); data_length = mxGetN(prhs[0])-1; nx = mxGetM(prhs[1]); if(mxGetN(prhs[1]) > nx) nx = mxGetN(prhs[1]); plhs[0] = mxCreateDoubleMatrix(nx, data_length, REAL); for(i=0;i