MATLAB: Trying to interpolate missing values of Z, given scattered data values of X and Y

3d plotsinterpolation

So I've finally found a reason to give MATLAB a whirl and I'm already running into some issues finding clear answers for this question. Either that or my inexperience is not allowing me to understand where to find exactly what I want.
Essentially I have a table in excel of X and Y values. These coordinates have a Z value, yet many (50-75%) are missing this value so I'd like MATLAB to interpolate or spline for these missing value to the best of it's ability. Just so y'all have an idea of what I'm talking about I'll attach a truncated data set in csv format.
My initial idea was to graph it all in a 3D scatter plot, fit a surface to it, then find the value where that surface interpolates over the missing data. My issue with this is (1) not knowing how to deal with the missing value going into MATLAB, should I input them as NaN? And (2) how to form a tight fitting surface to my data and not a best-fit equation of sorts.
My end goal is to just obtain these Z value estimates so if there's a better way of going about this I'm all ears. Thank y'all so much!

Best Answer

I'm not sure what you expected to see. Some magically smooth surface? A tool that will know what to do in those holes?
I filled in the missing z values with NaNs. Then just call gridfit .
[zgrid,xgrid,ygrid] = gridfit(x,y,z,0:10:370,-5:5:95);
surf(xgrid,ygrid,zgrid)
hold on
plot3(x,y,z,'ro')
I'm not too confident this is what you were hoping to see. Seriously bumpy data. Most techniques for interpolation will probably produce crap, including anything you might find in Excel, and I'm not too much in love with what gridfit did here either. But given what is little more than a randomly noisy bumpy scattered data set with big holes and lots of extrapolation needed, this is about as good as it will get using any tool.
You can just use interp2 to predict the values for each NaN element in z. Like this:
znan = isnan(z);
z(znan) = interp2(xgrid,ygrid,zgrid,x(znan),y(znan))
Note that since the holes in your data are pretty severe, and extrapolation is just a bad thing to do in general. So I'll make no claims about the goodness of this result, except to claim that a polynomial model would be seriously, massively worse.
You would need to download gridfit from the File Exchange to use it.