2D interpolation

I'm working with a data set in a 2D matrix, sometimes called "matrix of z-value", it's an 9 row by 16 column wave, no regularly spaced XY grid. I have two waves containing the source grid X and Y data. How do I make a linear interpolation?
You can use ImageInterpolate /W={xwave,ywave} XYWaves zMatrrix. If you do not have a version of IGOR that supports this you can use the procedure pasted below:

I hope this helps,

A.G.
WaveMetrics, Inc.

Function bilinearFromZMat(minx,dx,nx,miny,dy,ny,xWave,yWave,zMatrix)
    Variable minx,dx,nx,miny,dy,ny
    Wave xWave,yWave,zMatrix
    // first check that x&y waves have one more point than zMatrix:
    if(DimSize(xWave,0)-DimSize(zMatrix,0)!=1)
        doAlert 0,"Input x-wave should have 1 more point than the first dimension of zMatrix"
        return nan
    endif
    if(DimSize(yWave,0)-DimSize(zMatrix,1)!=1)
        doAlert 0,"Input y-wave should have 1 more point than the second dimension of zMatrix"
        return nan
    endif
   
    // Create the output wave:
    Make/O/N=(nx,ny)/Y=(WaveType(zMatrix)) M_InterpolatedValues
    SetScale/P x (minx),(dx),"", M_InterpolatedValues
    SetScale/P y (miny),(dy),"", M_InterpolatedValues
   
    M_InterpolatedValues=findZValue(x,y,xWave,yWave,zMatrix)
End


Function findZValue(inX,inY,xWave,yWave,zMatrix)
    Variable inX,inY
    Wave xWave,yWave,zMatrix
   
    findLevel/Q xWave,inX
    if(V_flag!=0 || GetRTError(1))
        return NaN
    endif
    Variable ax=V_Levelx
    Variable aa=trunc(ax)
    Variable alpha=ax-aa
    findLevel/Q yWave,inY
    if(V_flag!=0 || GetRTError(1))
        return NaN
    endif
    Variable ay=V_Levelx
    Variable bb=trunc(ay)
    Variable beta=ay-bb

    Variable outVal=(1-alpha)*(1-beta)*zMatrix[aa][bb]
            outVal+=(1-alpha)*beta*zMatrix[aa+1][bb]
            outVal+=alpha*(1-beta)*zMatrix[aa][bb+1]
            outVal+=alpha*beta*zMatrix[aa+1][bb+1]
    return outVal
End

Igor wrote:
You can use ImageInterpolate /W={xwave,ywave} XYWaves zMatrrix. If you do not have a version of IGOR that supports this you can use the procedure pasted below:

I hope this helps,

A.G.
WaveMetrics, Inc.



In this command you need xwave and ywave to be one point longer than the data set.
I have an MxN data wave and an M valued Xwave and an N-valued Ywave, which are not evenly spaced. is there a way to do this but where the x axis tells you the value of the centre of the point, and the the values of either side of the point? The latter is fine for regularly spaced data, but not so much for unevenly spaced data.
simon.wall wrote:

In this command you need xwave and ywave to be one point longer than the data set.


The "extra" point is a pain that is difficult to get around when you are displaying rectangular pixels of finite dimensions.

If your data consists of the centers only then you have two options:

1. Rearrange the data into an XYZ triplet wave and use ImageInterpolate with the keyword Voronoi. This will generate equally spaced data for display or further calculation.

2. Use ImageFromXYZ. This option is only useful for display purposes.

HTH,

A.G.
WaveMetrics, Inc.