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 Center および File ExchangeProgramming についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by