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?
Posts: 194
Joined: 2007-06-29
Location: United States
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"returnnanendifif(DimSize(yWave,0)-DimSize(zMatrix,1)!=1)doAlert 0,"Input y-wave should have 1 more point than the second dimension of zMatrix"returnnanendif// Create the output wave:Make/O/N=(nx,ny)/Y=(WaveType(zMatrix)) M_InterpolatedValues
SetScale/Px(minx),(dx),"", M_InterpolatedValues
SetScale/Py(miny),(dy),"", M_InterpolatedValues
M_InterpolatedValues=findZValue(x,y,xWave,yWave,zMatrix)EndFunction findZValue(inX,inY,xWave,yWave,zMatrix)Variable inX,inY
Wave xWave,yWave,zMatrix
findLevel/Q xWave,inX
if(V_flag!=0 || GetRTError(1))returnNaNendifVariable ax=V_Levelx
Variable aa=trunc(ax)Variable alpha=ax-aa
findLevel/Q yWave,inY
if(V_flag!=0 || GetRTError(1))returnNaNendifVariable ay=V_Levelx
Variable bb=trunc(ay)Variablebeta=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
Joined: 2007-06-29
Location: United States
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.
Joined: 2010-08-06
Location: Italy
Thank you very much. I solved my problem!