How to interpolate gridded matrix to a non-gridded one?
1 view (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Stephen23
on 8 Dec 2016
Edited: Stephen23
on 8 Dec 2016
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 Comments
Stephen23
on 8 Dec 2016
Edited: Stephen23
on 8 Dec 2016
@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');
More Answers (0)
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!