How to interpolate gridded matrix to a non-gridded one?

1 次查看(过去 30 天)
Hi all,
I'm struggling with an interpolation issue and I would really appreaciate some ideas on this. I have two matrixes, A and B, with A being non-gridded while B is gridded. I want to interpolate B for A grid points. I tried to build an interpolant function for A and then assess B through it, but I can't overcome the non-uniformity of A. Any thoughts that may help would be really appreaciated.
Thanks in advance
Joao

采纳的回答

Stephen23
Stephen23 2016-12-8
编辑:Stephen23 2016-12-8
Because your data points in B are gridded you can simply use any of the Gridded Data Interpolation tools. The fact that your sample points A are not gridded is totally irrelevant. Here is a simple example, adapted from the interp2 help:
% gridded data points:
[X,Y] = meshgrid(-3:3);
V = peaks(X,Y);
% non-gridded sample points:
Xq = 6*rand(1,1000)-3;
Yq = 6*rand(1,1000)-3;
%
Vq = interp2(X,Y,V,Xq,Yq);
%
scatter3(Xq,Yq,Vq);
  3 个评论
Stephen23
Stephen23 2016-12-8
编辑:Stephen23 2016-12-8
@Joao: you wrote in your question that you "want to interpolate B for A grid points", and that "A being non-gridded while B is gridded".
This is what I showed in my answer. X and Y are gridded (like your B), and Xq and Yq are non-gridded (like your A). I showed how to interpolate the gridded data at the non-gridded points, exactly as you requested: " I want to interpolate B for A grid points"
If you actually want to do the opposite, i.e. interpolate non-gridded data points A at gridded points B, then use griddata. Once again the locations of the output sample points is totally irrelevant. This example taken straight from the help:
% non-gridded data:
xy = -2.5 + 5*gallery('uniformdata',[200 2],0);
x = xy(:,1);
y = xy(:,2);
v = x.*exp(-x.^2-y.^2);
% grid points:
[xq,yq] = meshgrid(-2:.2:2, -2:.2:2);
% interpolate:
vq = griddata(x,y,v,xq,yq);
% plot
figure
mesh(xq,yq,vq);
hold on
plot3(x,y,v,'o');
Joao
Joao 2016-12-9
Hi Stephen,
Sorry for the confusion. You're right the first time. I've manage to solve the problem using TriScatteredInterp. When using interp2 has you suggested I got an error saying that my X and Y need to be generated using meshgrid. Thanks for your help!
João

请先登录,再进行评论。

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by