Input grid is not a valid MESHGRID
18 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Stephen23
il 28 Giu 2021
"...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);
Risposta accettata
KSSV
il 28 Giu 2021
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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Vector Fields in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!