Interpolation not-equally spacing data

13 次查看(过去 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
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?
user20912
user20912 2022-3-7
编辑:user20912 2022-3-7
The second one is the interpolated one, sorry for not indicate it. I have edit the post to clarify this.
I agree with you that the method should be chosen with a physical argument. However, the graphics is a way to check the results, right?
EDIT: In my approach, what I'm trying to do. Is to reproduce my var over a more fine grid. I don't know if this is the right place to ask this, but anyhow... How should I decide which method to use?

请先登录,再进行评论。

回答(1 个)

Star Strider
Star Strider 2022-3-7
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.

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

标签

产品


版本

R2017a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by