How to create different Plots for different functions while each function has been plotted using hold on
조회 수: 5 (최근 30일)
이전 댓글 표시
I created a code to calculate entropy and enthalpy for different pressures (which forms my x axis) at different temperatures.
I want to plot isotherms for enthalpy and using hold on, multiple isotherms in the same plot.
But using "hold on" not only clubs the different isotherms for enthalpy together in one plot, but also clubs entropy isotherms into the same plot too. Due to the difference in order of magnitude between the two, the entropy lines are simply not visible. Scaling enthalpy down by 10^3 has helped in making both of them visible but I want them to be in seperate graphs or plots.
%enthalpy plot (KJ/mol Vs Bar)-
hold on;
for t = 1:nt %varying temperature to create isotherms
for p = 1:np
enth(1, p) = 0.001*enthalpy(T(1, t), P(1, p), [T_ref, P_ref, H_ref], [A B], [a b c], R);
end
plot1 = plot(P, enth); %one plot for particular value of temperature
end
hold off
%entropy plot (J/K Vs Bar)-
hold on
for t = 1:nt
for p = 1:np
ent(1, p) = entropy(T(1, t), P(1, p), [T_ref, P_ref, S_ref], [A B], [a b c], R);
end
plot2 = plot(P, ent);
end
the indivisual functions of entropy and enthalpy are trivial, the long list of arguments is basically temperature and pressure that i want to calculate the function in plus the refernce states and constants.
댓글 수: 0
채택된 답변
dpb
2022년 9월 6일
%enthalpy plot (KJ/mol Vs Bar)-
hold on;
for t = 1:nt %varying temperature to create isotherms
for p = 1:np
enth(1, p) = enthalpy(T(1, t), P(1, p), [T_ref, P_ref, H_ref], [A B], [a b c], R);
end
plot1 = plot(P, enth); %one plot for particular value of temperature
end
figure
%entropy plot (J/K Vs Bar)-
hold on
for t = 1:nt
for p = 1:np
ent(1, p) = entropy(T(1, t), P(1, p), [T_ref, P_ref, S_ref], [A B], [a b c], R);
end
plot2 = plot(P, ent);
end
What you missed is simply creating a new figure for the second plot.
As a stylistic and computing note; if the two functions enth and entropy were vectorized, then you could simply call them with the T,P arrays and get back the arrays of results eliminating the looping at the outer level.
댓글 수: 3
dpb
2022년 9월 6일
That's what I put in the code I posted in the Answer -- just insert the figure command and presto! a whole new figure window appears....
추가 답변 (1개)
Cris LaPierre
2022년 9월 6일
Perhaps what you need is to create a plot with two y axes, one for entropy and the other for enthalpy? If so, use yyaxis.
x = linspace(0,10);
y = sin(3*x);
yyaxis left
plot(x,y)
z = sin(3*x).*exp(0.5*x);
yyaxis right
plot(x,z)
ylim([-150 150])
댓글 수: 2
Cris LaPierre
2022년 9월 6일
Then you need to create a new figure for each one before plotting. Use the figure command
x = linspace(0,10);
y = sin(3*x);
plot(x,y)
figure
z = sin(3*x).*exp(0.5*x);
plot(x,z)
ylim([-150 150])
참고 항목
카테고리
Help Center 및 File Exchange에서 Time Series Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!