필터 지우기
필터 지우기

Only one graph appear instead of two.

조회 수: 1 (최근 30일)
N/A
N/A 2022년 8월 28일
답변: dpb 2022년 8월 28일
Hello, so I'm trying to plot a graph using Antoine equation. I was given two equation and was tasked to plot a graph. Unfortunately, when I run the code, only 1 graph appear instead of 2 and I don't know where I go wrong. Help is greatly appreciated. Thank you.
Below is the code I use as reference.
A1=14.895;
B1=-3412.1;
C1=-22.627;
A2=14.751;
B2=-3331.7;
C2=-45.55;
D=30:75; %temperature range required
T=D+273; %converted to Kelvin
log10P=A1-B1./(T+C1); %Antoine's equation
Psat1 = 10.^log10P; %Computing Psat1
log10P=A2-B2./(T+C2); %Antoine's equation
Psat2 = 10.^log10P; %Computing Psat2
plot(D,Psat1,D,Psat2,'.-');
xlabel('Temperature [K]');
ylabel('Pressure [kPa]');
title('Saturation Pressure from Antoine Equation');
plot(T,Psat1,'r');
plot(T,Psat2,'b');
legend('Psat1', 'Psat2')
grid on;

채택된 답변

Star Strider
Star Strider 2022년 8월 28일
Use the hold function —
A1=14.895;
B1=-3412.1;
C1=-22.627;
A2=14.751;
B2=-3331.7;
C2=-45.55;
D=30:75; %temperature range required
T=D+273; %converted to Kelvin
log10P=A1-B1./(T+C1); %Antoine's equation
Psat1 = 10.^log10P; %Computing Psat1
log10P=A2-B2./(T+C2); %Antoine's equation
Psat2 = 10.^log10P; %Computing Psat2
figure
plot(D,Psat1,D,Psat2,'.-')
hold on % <— ADDED
xlabel('Temperature [K]');
ylabel('Pressure [kPa]');
title('Saturation Pressure from Antoine Equation');
plot(T,Psat1,'r')
plot(T,Psat2,'b')
hold off % <— ADDED
legend('Psat1', 'Psat2', 'Location','best')
grid on;
.

추가 답변 (1개)

dpb
dpb 2022년 8월 28일
You forgot
hold on
to put more on the same axes after the first...
plot(T,Psat1,'r');
hold on
plot(T,Psat2,'b');
title('Saturation Pressure from Antoine Equation');
...
will do the deed -- as will for somewhat more compact code
plot(T,Psat1,'r-',T,Psat2,'b-');
without the need for hold on. Or,
...
D=(30:75).'; % make the independent variable a column vector so results will be, too...
...
hL=plot(T,[Psat1,Psat2]); % use plot() by column inbuilt feature, save line handles
...
For the last, the typical default line colors start with 'r', 'b' so you'll get those by default if that default order hasn't been redefined. It it has, that's the reason saved the line handles; the final step would be
set(hL,{'Color'},{'r';'B'}) % set colors explicitly
All the various syntax options are in the doc for plot; it's far more flexible than simply "one-at-a-time" use.

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by