MATLAB: Surface interpolation based on x/y/diagonals data

gridddataMATLABmissing datasurface interpolatio

Hi,
is it feasable to interpolate data if we only have the x, y cross sections and the diagonals?
exp:
a =
10 0 0 0 0 10 0 0 0 0 10
0 9 0 0 0 9 0 0 0 9 0
0 0 8 0 0 8 0 0 8 0 0
0 0 0 7 0 7 0 7 0 0 0
0 0 0 0 6 6 6 0 0 0 0
10 9 8 7 6 5 6 6 8 9 10
0 0 0 0 6 6 6 0 0 0 0
0 0 0 7 0 7 0 7 0 0 0
0 0 8 0 0 8 0 0 8 0 0
0 9 0 0 0 9 0 0 0 9 0
10 0 0 0 0 10 0 0 0 0 10
can I interpolate the zero data?
I tried griddedInterpolant, interpn, griddata but it doesn't work.
Thank you

Best Answer

By far the simplest solution is to use inpaint_nans. It will produce a surface, interpolating those empty areas. (However, you saidthat you tried tools like griddata, etc. If you used them properly for this problem, griddata or scatteredInterpolant would both have worked.
Just insert a NaN element where ever you lack data. I'dcreate the array as full of NaNs, then insert your datainto the known elements. Or, in thiscase, I'll just replace all zero elements with a NaN. Then call inpaint_nans.
a = [ 10 0 0 0 0 10 0 0 0 0 10
0 9 0 0 0 9 0 0 0 9 0
0 0 8 0 0 8 0 0 8 0 0
0 0 0 7 0 7 0 7 0 0 0
0 0 0 0 6 6 6 0 0 0 0
10 9 8 7 6 5 6 7 8 9 10
0 0 0 0 6 6 6 0 0 0 0
0 0 0 7 0 7 0 7 0 0 0
0 0 8 0 0 8 0 0 8 0 0
0 9 0 0 0 9 0 0 0 9 0
10 0 0 0 0 10 0 0 0 0 10];
a(a == 0) = NaN;
The different methods will produce slightly different behaviior. Note that as you have constructed the fake data here, if the interpolation were to produce a linear interpolation across those holes, then you must get sharp creases along the diagonals.
b = inpaint_nans(a,2);
Whereas an interpolation that tries to be smooth will produce scallops along the sides of the array when plotted as a surface.
b = inpaint_nans(a,0);
Both surfaces produced make sense.