Hello, I'm trying to read the data in the zip file attached with this code but I'm getting errors, not sure how I could plot the data contained in this file? any help will be greatly appreciated. Thanks
clear;
clc;
nx=225;ny=66;nfields=9;
a=readmatrix('NACA4612_1E-4_225x66.XYZ_M=0.5_ALPHA_2.0_Turbulent.dat','Headerlines',5)';
b=reshape(a(1:nx*ny*2),[nx,ny,2]);
x=b(:,:,1);y=b(:,:,2);
%centroids (improve this by averaging the 4 corners)
xc=x(1:end-1,1:end-1)+diff(x(:,1:end-1))/2 +diff(x(1:end-1,:),[],2)/2;
yc=y(1:end-1,1:end-1)+diff(y(:,1:end-1))/2 +diff(y(1:end-1,:),[],2)/2;
b=reshape(a(nx*ny*2+1:end),[nx-1,ny-1,nfields]);%nine dependent variables
%plot pressure
figure;surf(xc,yc,b(:,:,4));
view(2);shading flat;axis image;axis([-1,1,-1,1])

댓글 수: 5

MATLAB R2023a has not problem reading it, however there does not appear to be much to see in the plot —
Uz = unzip('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1370564/NACA4512_1E-4_225x66.XYZ_M=0.5_ALPHA_2.0_TURBULENT.dat.zip');
a = readmatrix(Uz{1})
a = 16074×10
0.5011 0.5011 0.5010 0.5010 0.5009 0.5008 0.5007 0.5006 0.5005 0.5003 0.5002 0.5000 0.4998 0.4997 0.4995 0.4993 0.4991 0.4989 0.4986 0.4983 0.4979 0.4975 0.4970 0.4964 0.4958 0.4950 0.4942 0.4932 0.4920 0.4908 0.4893 0.4876 0.4856 0.4834 0.4808 0.4779 0.4746 0.4708 0.4664 0.4615 0.4559 0.4495 0.4422 0.4340 0.4248 0.4144 0.4027 0.3897 0.3751 0.3590 0.3412 0.3216 0.3002 0.2770 0.2519 0.2251 0.1965 0.1664 0.1348 0.1022 0.0686 0.0344 0 -0.0344 -0.0684 -0.1017 -0.1341 -0.1653 -0.1950 -0.2232 -0.2496 -0.2743 -0.2972 -0.3183 -0.3376 -0.3552 -0.3712 -0.3856 -0.3986 -0.4103 -0.4207 -0.4300 -0.4382 -0.4456 -0.4521 -0.4578 -0.4629 -0.4674 -0.4714 -0.4749 -0.4779 -0.4807 -0.4831 -0.4852 -0.4870 -0.4886 -0.4901 -0.4913 -0.4925 -0.4935
% clear;
% clc;
nx=225;
ny=66;
nfields=9;
% a=readmatrix('NACA4612_1E-4_225x66.XYZ_M=0.5_ALPHA_2.0_Turbulent.dat','Headerlines',5)';
b=reshape(a(1:nx*ny*2),[nx,ny,2]);
x=b(:,:,1);
y=b(:,:,2);
%centroids (improve this by averaging the 4 corners)
xc=x(1:end-1,1:end-1)+diff(x(:,1:end-1))/2 +diff(x(1:end-1,:),[],2)/2;
yc=y(1:end-1,1:end-1)+diff(y(:,1:end-1))/2 +diff(y(1:end-1,:),[],2)/2;
b=reshape(a(nx*ny*2+1:end),[nx-1,ny-1,nfields]);%nine dependent variables
bSz = size(b)
bSz = 1×3
224 65 9
%plot pressure
figure
surf(xc,yc,b(:,:,4))
view(2)
shading flat
axis image
axis([-1,1,-1,1])
.
thanks I can visualize it better now. However, for this case I'm gettng this error, not sure how to fix it.?? Any help will be appreciated. thanks
b=reshape(a(1:nx*ny*2),[nx,ny,2]);
x=b(:,:,1);
y=b(:,:,2);
%centroids (improve this by averaging the 4 corners)
xc=x(1:end-1,1:end-1)+diff(x(:,1:end-1))/2 +diff(x(1:end-1,:),[],2)/2;
yc=y(1:end-1,1:end-1)+diff(y(:,1:end-1))/2 +diff(y(1:end-1,:),[],2)/2;
b=reshape(a(nx*ny*2+1:end),[nx-1,ny-1,nfields]);%nine dependent variables
bSz = size(b)
Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for
that dimension.
xc=x(1:end-1,1:end-1)+diff(x(:,1:end-1))/2 +diff(x(1:end-1,:),[],2)/2;
yc=y(1:end-1,1:end-1)+diff(y(:,1:end-1))/2 +diff(y(1:end-1,:),[],2)/2;
b=reshape(a(nx*ny*2+1:end),[nx-1,ny-1,nfields]);%nine dependent variables
Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically calculate the appropriate size for
that dimension.
Cris LaPierre
Cris LaPierre 2023년 5월 3일
Just work out the math. The number of elements in a(nx*ny*2+1:end) is not the same as the number of elements in [nx-1,ny-1,nfields].
Cesar Cardenas
Cesar Cardenas 2023년 5월 3일
Thanks, I've been trying that, but I have not been able to figure it out. can you give me a bit more detail? Thanks
Cris LaPierre
Cris LaPierre 2023년 5월 4일
Sure. Can you provide the values of nx, ny, and nfields at this point in your code?

댓글을 달려면 로그인하십시오.

답변 (1개)

Debraj Maji
Debraj Maji 2023년 11월 14일

0 개 추천

I see that you are trying to read data form a file with a .DAT extension. I have downloaded the zip file shared and upon inspection have found that there is a mismatch in the file name used for reading the file. You can find the required correction below:
a=readmatrix('NACA4512_1E-4_225x66.XYZ_M=0.5_ALPHA_2.0_TURBULENT.dat','Headerlines',5)';
The corresponding figure obtained using the shared data is attached below:
Make sure to add the path for the data file is added before the script is run.
I hope this helps!

카테고리

도움말 센터File Exchange에서 MATLAB에 대해 자세히 알아보기

태그

질문:

2023년 4월 30일

답변:

2023년 11월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by