Creating a grid from a 2D scatter plot of vectors

12 次查看(过去 30 天)
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 个评论
Roisin Coveney
Roisin Coveney 2021-6-22
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.

请先登录,再进行评论。

采纳的回答

KSSV
KSSV 2021-6-22
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 个评论
Roisin Coveney
Roisin Coveney 2021-6-22
Sorry will do that now, my first time asking a question so I didn't know!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by