Borrar filtros
Borrar filtros

Reshaping the velocity data to match with generated meshgrid of x and y to further plot contour of velocity?

2 visualizaciones (últimos 30 días)
Hi,
I have some CFD data on a plane. The data include x,y,z,u,v, and w information. I have read the data and further doing proper orthognal decomposition on this data but I know how to do that.
Here I have created a very simple matrix to understand what reshape and other functions does.
%Test code%
xmin=1; xmax=10; ymin=1; ymax=5;
x=linspace(xmin,xmax,10);
y=linspace(ymin,ymax,10);
[X,Y]=meshgrid(x,y);
U=10.1:0.1:11;
V=U';
U_reshaped= reshape(U(zeros(10^2,1), X(:), Y(:)), [10 10]);
This is the code I am trying on my large CFD data. However this last command "reshape" is not working. I ma getting following error below. I have copied this command from another example where it is working perfectly fine in the same format.
"Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in Untitled (line 22)
U_reshaped= reshape(U(zeros(10^2,1), X(:), Y(:)), [10 10]);"
I am very new to matlab. I would highly appriciate any help.
Thanks

Respuestas (1)

Cris LaPierre
Cris LaPierre el 18 de Ag. de 2021
Editada: Cris LaPierre el 18 de Ag. de 2021
Your error is referring to this command: U(zeros(10^2,1))
You have already defined U, so the zeros are being interpretted as indices. You cannot use 0 as an index. In MATLAB, indexing begins at 1.
  1 comentario
Muhammad Atif
Muhammad Atif el 18 de Ag. de 2021
Hi Chris,
Thank you for your reply. I actually copied this command from someone else code where he also defined U matrix before which was about 33000 by 1 and he was using this remesh command to generate a 200 by 200 grid "U_reshaped= reshape(U(zeros(200^2,1), X(:), Y(:)), [200 200]);" Here both X and Y are also 200 by 200 matrix. and the command was working fine generating U_reshaped 200 by 200.
Anyway I used griddata command to populate U,V and W on meshgrid. code is below. It seems working fine but only problem is that the boundary is not captured very smoothly and scaled differently as comapred to CFD results. ANy help on capturing the boundary properly would be highly appriciated.(see pictures)
X1=min(X):0.1:max(X); Y1=min(Y):0.1:max(Y);
[xmesh, ymesh] = meshgrid(X1,Y1);
[x1 y1 u1]=griddata(X,Y,U,xmesh,ymesh);
[x1 y1 v1]=griddata(X,Y,V,xmesh,ymesh);
[x1 y1 w1]=griddata(X,Y,W,xmesh,ymesh);
Thanks

Iniciar sesión para comentar.

Categorías

Más información sobre Computational Fluid Dynamics (CFD) en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by