Input grid is not a valid MESHGRID

54 次查看(过去 30 天)
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 个评论
Curtis Lam
Curtis Lam 2021-6-28
I'm attaching the struct from using the loadvec function
Stephen23
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);

请先登录,再进行评论。

采纳的回答

KSSV
KSSV 2021-6-28
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(min(A.x),max(A.x),500);
yq = linspace(min(A.y),max(A.y),500);
[Xq,Yq] = meshgrid(xq,yq);
velocitydata = A.vx;
velocitydata2= A.vy;
B = interp2(Xprime,Yprime,velocitydata',Xq,Yq, 'spline')';
C = interp2(Xprime,Yprime,velocitydata2',Xq,Yq,'spline')';
figure(2);
quiver(Xq,Yq,B',C')
  2 个评论
Curtis Lam
Curtis Lam 2021-6-28
the resulting quiver plot does look like what i'm looking for.. but could i ask why I cannot use my previous linspace parameters for xq and yq?
KSSV
KSSV 2021-6-28
You can use that as well.....

请先登录,再进行评论。

更多回答(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