Interpolation not-equally spacing data
9 views (last 30 days)
I'm working with the following data:
Name Size Bytes Class
X 136x1 544 single
Y 32x136 17408 single
var 32x136 17408 single
Where X is equally spaced data but Y is not. Y represent depth in meters (negative values) and I'm trying to interpolate to a finner grid. I have use two approaches:
- Trying with INTERP1. In this case, I first remove depths lower than 20m, then interpolate "column by column":
for i1 = 1:size(Y,2)
DEP = Y(:,i1);
% If the column depth is bigger than -20m
if min(fix(DEP)) < -20;
zx = -20:1:0;
% If the column depth if smaller than -20m
zx = min(fix(DEP)):1:0;
out_var(1:size(zx,2),i1) = interp1(DEP,var(:,i1),zx,'nearest','extrap');
new_dep(1:size(zx,2),i1) = zx;
However, the results are not very good. The upper (lower) panel in the figure show the original (interpolated) data.
I need a better interpolation in the right side because of the gradient. I already have tried with the different method in interp1 but non of theses have work as I need it. I also have tried smooting this result but I get a worse result.
- Then, I tried with interp2 (In the x-data I keep the same spacing as X):
[x,y] = meshgrid(x(1):0.0333:x(end),-60:1:0);
new_var = interp2(X,Y,var,x,y );
But I get the following error:
Error using interp2>makegriddedinterp
Input grid is not a valid MESHGRID.
Error in interp2
F = makegriddedinterp(X, Y, V, method,extrap);
Is there another aproach to get a better interpolation?
Thanks in advance,
Star Strider on 7 Mar 2022
I generally use griddata for these sorts of problems.
I cannot determine if it will produce the desired result since I don’t have your data to experiment with. It has generally produced satisfactory results when I’ve used it.