I have an array [160,160] with 27 measured data points and you want to interpolate the entire array. I found the following code, but I don’t understand what parameters I need to pass in order for this method to work:
public static double BilinearInterpolation(double[] x, double[] y, double[,] z, double xval, double yval)
{
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)
{
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 → x the coordinates of my points in the array?
double [] y → y coordinate my points in an array?
double [,] z → an array where the interpolated values are stored?
double xval → ??
double yval → ??
It is right? or maybe you have an easier way to interpolate an array with bilinear.
source
share