Interpolation not-equally spacing data
11 views (last 30 days)
Show older comments
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
Jan
on 7 Mar 2022
Edited: Jan
on 7 Mar 2022
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?
Answers (1)
Star Strider
on 7 Mar 2022
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.
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!