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
KSSV 2021 年 6 月 28 日
Check the dimensions of X, Y, A.vx. Do they have same dimensions?
Curtis Lam
Curtis Lam 2021 年 6 月 28 日
hi KSSV,
so I had loaded in a struct with a value A.x with 62 x values, A.y with 63 y values, and A.vx which is 62x63 (as you can see it corresponds to A.x and A.y)
So when I mesh grid, X and Y becomes 63x62.
KSSV
KSSV 2021 年 6 月 28 日
Attach your data.
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 日

0 投票

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 件)

カテゴリ

ヘルプ センター および File ExchangeVector Fields についてさらに検索

質問済み:

2021 年 6 月 28 日

コメント済み:

2021 年 6 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by