Creating a grid from a 2D scatter plot of vectors

조회 수: 11 (최근 30일)
Roisin Coveney
Roisin Coveney 2021년 6월 22일
댓글: Roisin Coveney 2021년 6월 22일
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
Dhruv G
Dhruv G 2021년 6월 22일
yeah, so that's u and v, each with 1 value...
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
KSSV
KSSV 2021년 6월 22일
Thanks is accepting/ voting the answer. :)
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