Creating a grid from a 2D scatter plot of vectors

40 visualizzazioni (ultimi 30 giorni)
So I have a list of x positions, y positions, x velocity and y velocity, I want to turn this in to 4 grid matrices with (i,j) from each of the 4 matrices corresponding to the values for x,y,u,v from the list above with the x, y values being in order in terms of their physical position. I have tried to just reshape the matrices but this isnt working and tried griddata but as I have two values for the velocity it wont work as v needs to be just a single value, and the velocity values are essentially random, so i can't create a fucntion that defines them over the domain, and if I get the resultant velocity vector this only defines the magnitude and not the direction.
I need to do this so I can do partial differentiation using the finite difference scheme. Does anyone have any suggestions as to how I might do this?
  5 Commenti
Dhruv G
Dhruv G il 22 Giu 2021
yeah, so that's u and v, each with 1 value...
Roisin Coveney
Roisin Coveney il 22 Giu 2021
Sorry so I think I was a bit unclear there. I was trying to use this fucntion vq = griddata(x,y,v,xq,yq). where v = f(x,y). When I say my V has two values I mean that the values that I am trying to define along each x and y position are velcoities say, ux and uy, instead of u and v to avoid confusion. In this fucntion though v can only have one value, and I cant define my velocity only in terms of its magnitude as I los the information about the direction of the veloicty vector.
Maybe I should use a different method than griddata, I just need to create 4 matrices where the (i, j) value from each matrix corresponds to eachother in the velcoity field. I just wanted the x and y values in the matrix to corrspond to their positions reative to each other so that I can make a for loop which calculates du/dx, dv/dy etc for each vector using finite difference scheme, I know there are functions to do partial differentiation in matlab but it seems that they are based on differentiatng a function and not discrete values. The velocity values are essentially random as they are velocity vectors obtained using PIV.

Accedi per commentare.

Risposta accettata

KSSV
KSSV il 22 Giu 2021
Let x, y, xvel, yvel be your data.
m = 100 ; n = 100;
x = linspace(min(x),max(x),m) ;
y = linspace(min(y),max(y),n) ;
[X,Y] = meshgrid(x,y) ;
u = griddata(x,y,xvel,X,Y) ;
v = griddata(x,y,yvel,X,Y) ;
quiver(X,Y,u,v)
  5 Commenti
KSSV
KSSV il 22 Giu 2021
Thanks is accepting/ voting the answer. :)
Roisin Coveney
Roisin Coveney il 22 Giu 2021
Sorry will do that now, my first time asking a question so I didn't know!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by