Unable to generate a proper contour plot

조회 수: 6 (최근 30일)
Bamelari Jovani
Bamelari Jovani 2024년 10월 11일
댓글: Bamelari Jovani 2024년 10월 11일
Greetings everyone,
I am trying to generate a contour plot of mach number. I have provided the code below as well as my output(PLOT.PNG). The output is not what I want. I want it to be completely filled with colours of mach number. I have attached the necessary files obtained from ANSYS FLUENT(ZIP file).
Any help is appreciated!
clc; clearvars; close all; % clear my workspace
% import the data
pname = '[insert directory here]';
fname = 'interior.dat'; % data from ANSYS FLUENT
prof_name = 'boundary_data.dat';
% reference variables
%ur = 127.54; % in m/s
%pr = 272609; % in Pa
Lr = 0.03989;%.3422e-3; % in m
% reading the file
a = importdata(strcat(pname,fname));
b = importdata(strcat(pname,prof_name));
% collecting variables
x = a.data(:,2); y = a.data(:,3); M = a.data(:,4);
% profile
xp = b.data(:,2) ; yp = b.data(:,3);
%%
% creating a matrix data or a structured data
xu = unique(round(x,4)); yu = unique(round(y,4)); % for better memory
[xm,ym] = meshgrid(xu,yu);
%% interpolate
Mm = griddata(x,y,M,xm,ym);
%um = griddata(x,y,u,xm,ym);
%vm = griddata(x,y,v,xm,ym);
%pm = griddata(x,y,p,xm,ym);
%% set undefined values outside the fluid domain
in = inpolygon(xm,ym,xp,yp);
xm(~in) = NaN; ym(~in) = NaN; Mm(~in) = NaN;
%% plot
%subplot(2,2,1)
%contourf(xm, ym, Mm, 'LineColor', 'none');
pcolor(xm,ym,Mm);shading interp; hold on;
plot(xp,yp,'.k'); hold off; axis equal;
clb = colorbar;
title(clb,'M');
xlabel('x/D');ylabel('y/D');
set(clb,'TickDir','out');
set(gca,'TickDir','out','layer' , 'top');
  댓글 수: 2
Umeshraja
Umeshraja 2024년 10월 11일
Hello @Bamelari Jovani, it seems that the zip file is either corrupted or possibly empty, as I'm unable to extract it.
Bamelari Jovani
Bamelari Jovani 2024년 10월 11일
Dear @Umeshraja You can find the files here: https://drive.google.com/drive/folders/158I7MfqUD9yIXbiOkg7FYf0KYgu-OpXh?usp=sharing

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

답변 (1개)

Umeshraja
Umeshraja 2024년 10월 11일
The lines highlighted below are indeed attempting to mask areas outside the fluid domain to prevent plotting data where it doesn't physically exist. However, this approach can sometimes cause problems, especially if the boundary isn't well-defined.
in = inpolygon(xm,ym,xp,yp);
xm(~in) = 0; ym(~in) = 0; Mm(~in) = 0;
Removing these lines result in contour plot completely filled with colours representing mach number as shown below.
Hope it helps!

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by