필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Joao
Joao 2016년 12월 8일
댓글: Joao 2016년 12월 9일
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