I am using griddata on a scattered datatset (Data) to 'map' it onto a regular grid. The data is 2D and of the form: Data.x, Data.y, Data.z. The original data has some 'gaps'. All Data.x and Data.y values are valid with the 'gaps' being identified by Data.z = 0, and the remaining Data.z values are valid. Using griddata seems to still use these 'gap' data points and produces an output where the gaps are interpolated across using the surrounding 'valid' values. My code is as follows:
Data.Zgridded = griddata(Data.x, Data.y, Data.z, xgrid, ygrid);
where xgrid and ygrid are created using meshgrid.
My objective is to interpolate the scattered data onto a regular grid but omitting the 'gaps' from the interpolation (or assigning the gaps to NaNs or otherwise). Masking the data after griddata does not produce the correct result as the 'gap' data points are currently being incorrectly included in the first instance.
Any thoughts on how to tackle this are greatly appreciated.
Best Answer