Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
Joao
Joao am 8 Dez. 2016
Kommentiert: Joao am 9 Dez. 2016
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

Akzeptierte Antwort

Stephen23
Stephen23 am 8 Dez. 2016
Bearbeitet: Stephen23 am 8 Dez. 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 Kommentare
Stephen23
Stephen23 am 8 Dez. 2016
Bearbeitet: Stephen23 am 8 Dez. 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');
Joao
Joao am 9 Dez. 2016
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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Interpolation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by