Interpolation not-equally spacing data

9 views (last 30 days)
user20912
user20912 on 7 Mar 2022
Edited: user20912 on 7 Mar 2022
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 Comments
user20912
user20912 on 7 Mar 2022
Edited: user20912 on 7 Mar 2022
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?

Sign in to comment.

Answers (1)

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

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!