Input grid is not a valid MESHGRID
이전 댓글 표시
I am trying to interpolate values with interp2 but it gives the error: input grid is not a valid meshgrid. I've used interp2 before but the only change i made this time was transpose the X,Y matrices so that it matches with the output matrix I have.
Particularly, I need help wrapping my head around X and Y coordinates for the interp2 since it does not seem to work. I had initially transposed the X and Y meshgrids because my raw data was a 62x63 matrix with 62 x position and 63 y positions, but the meshgrids were 63x62. I was able to make a quiver plot successfully doing this.

Now, I need to interpolate this raw data across a finer resolution/sampling with interpolation with interp2. However, I am confused why I cannot do this easily with interp2 but for some reason it works when i switch my X and Y transposed meshgrids (see variables B and C). However the resulting quiver plot looks inaccurate and just wrong.
A= loadvec('2009-08-07_measurements_22mi_e16900.T001.D001.P001.H001.L.vec');
[X,Y] = meshgrid(A.x,A.y);
Xprime = X';
Yprime = Y';
quiver(Xprime,Yprime,A.vx,A.vy)
xq = linspace(0,23,500);
yq = linspace(0,23,500);
[Xq,Yq] = meshgrid(xq,yq);
velocitydata = A.vx;
velocitydata2= A.vy;
B = interp2(Yprime,Xprime,velocitydata,Xq,Yq, 'spline');
C = interp2(Yprime,Xprime,velocitydata2,Xq,Yq,'spline');
figure(2);
quiver(Xq,Yq,B,C)
댓글 수: 5
KSSV
2021년 6월 28일
Check the dimensions of X, Y, A.vx. Do they have same dimensions?
Curtis Lam
2021년 6월 28일
KSSV
2021년 6월 28일
Attach your data.
Curtis Lam
2021년 6월 28일
Stephen23
2021년 6월 28일
"...but the only change i made this time was transpose the X,Y matrices..."
Which exactly why you are getting that error message: interpolation routines require data to be in particular way, and by transposing those matrices you have arranged the data differently.
If you want to use INTERP2, then consider swapping the order of the inputs and outputs:
[Y,X] = meshgrid(A.y,A.x);
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Vector Fields에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!