Creating a contour plot with three row vectors

조회 수: 4 (최근 30일)
Rami Abdelhadi
Rami Abdelhadi 2022년 4월 24일
편집: DGM 2022년 4월 24일
I need to create a contour plot, but my input consists of three row vectors, x_isen, y_isen, and M_isen. At each coordinate of (x_isen,y_isen), I have a value of M_isen. Also M_isen only varies in the x direction so it is constant for all y values at each x coordinate. My y_isen vector is currently all zeros because I am unsure how to make it otherwise even though it should be all y values at each x. My goal is to create a similar plot as I have attached below. Please help!
figure (1)
hold on
grid on
contourf (x_isen,y_isen,M_isen,500,'LineStyle','none')
xlabel('Nozzle Length (m)')
ylabel('Nozzle Height (m)')
title('Mach Value Through Nozzle')
%% Overlay Nozzle Contour
for j=2:n_left_wave
plot([x(j-1,nwave+1);x(j,nwave+1)],[y(j-1,nwave+1);y(j,nwave+1)],...
'k','LineWidth',3)
end
% Set some limits on the axes
ylim([0, h_exit*.55]);
xlim([0, length]);
colorbar
colormap('jet')
caxis([1 3])
daspect([1,1,1]);
hold off

채택된 답변

DGM
DGM 2022년 4월 24일
편집: DGM 2022년 4월 24일
I answered a similar question recently.
The only real difference is that the boundary shape would be straight lines.
% the inputs
x = linspace(0,1,25);
ytop = 0.05 + 0.2*x;
ybot = zeros(size(x));
T = 1 + x*2; % some arbitrary flow data
% plot a patch
hp = patch([x fliplr(x)],[ybot fliplr(ytop)],[T fliplr(T)]);
hp.EdgeColor = 'none';
hold on; grid on
% plot curves last
axis([0 1 0 0.3]);
plot(x,ytop,'k','linewidth',2);
% add a colorbar
colormap(jet)
hcb = colorbar;
If you want the stepped appearance of a contourf() plot (at least without the lines), you could use a shorter colormap.
If you truly want to do it with contourf(), you'll have to replicate your M vector into a 2D array. This is a similar example showing a truncated pcolor()/contourf() plot

추가 답변 (0개)

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by