I have an array[160,160] with 27 measured datapoints and want to interpolate the whole array. I have found the following code, but don't get it which parameters I have to hand over so that this method works:
public static double BilinearInterpolation(double[] x, double[] y, double[,] z, double xval, double yval)
{
//calculates single point bilinear interpolation
double zval = 0.0;
for (int i = 0; i < x.Length - 1; i++)
{
for (int j = 0; j < y.Length - 1; j++)
{
if(xval>=x[i] && xval<x[i+1] && yval>=y[j] && yval<y[j+1])
{
zval = z[i,j]*(x[i+1]-xval)*(y[j+1]-yval)/(x[i+1]-x[i])/(y[j+1]-y[j])+
z[i+1,j]*(xval-x[i])*(y[j+1]-yval)/(x[i+1]-x[i])/(y[j+1]-y[j])+
z[i,j+1]*(x[i+1]-xval)*(yval-y[j])/(x[i+1]-x[i])/(y[j+1]-y[j])+
z[i+1,j+1]*(xval-x[i])*(yval-y[j])/(x[i+1]-x[i])/(y[j+1]-y[j]);
}
}
}
return zval;
}
public static double[] BilinearInterpolation(double [] x, double[] y, double[,]z,double[] xvals, double[]yvals)
{
//calculates multiple point bilinear interpolation
double[] zvals = new double[xvals.Length];
for (int i = 0; i < xvals.Length; i++)
zvals[i] = BilinearInterpolation(x, y, z, xvals[i], yvals[i]);
return zvals;
}
double[] x --> the x koordinates of my points in an array?
double[] y --> the y koordinates of my points in an array?
double[,] z --> an array, where the interpolated values get stored?
double xval --> ??
double yval --> ??
is this correct? or maybe you have a easier way to interpolate the array bilinear.