read data to plot

조회 수: 3 (최근 30일)
Cesar Cardenas
Cesar Cardenas 2023년 4월 30일
답변: Debraj Maji 2023년 11월 14일
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
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일
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!

태그

Community Treasure Hunt

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

Start Hunting!

Translated by