Unable to generate a proper contour plot
6 次查看(过去 30 天)
显示 更早的评论
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
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.
回答(1 个)
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 Center 和 File Exchange 中查找有关 Contour Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!