Interpolation not-equally spacing data
14 次查看(过去 30 天)
显示 更早的评论
Hi.
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;
else
% If the column depth if smaller than -20m
zx = min(fix(DEP)):1:0;
end
out_var(1:size(zx,2),i1) = interp1(DEP,var(:,i1),zx,'nearest','extrap');
new_dep(1:size(zx,2),i1) = zx;
end
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,
2 个评论
Jan
2022-3-7
编辑:Jan
2022-3-7
It is a mathematical difference, if you interpolate in 1 or 2 dimensions. You have to decide for the method, with matchs your model. You cannot simply choose the method, which produces the nicer graphics.
It matters if you choose "nearest" or "linear" interpolation. You need a physical argument to decide for the matching method.
You post 2 graphics. Which on is the interpolated one?
回答(1 个)
Star Strider
2022-3-7
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.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!