How to create different Plots for different functions while each function has been plotted using hold on
5 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
dpb
on 6 Sep 2022
%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 Comments
dpb
on 6 Sep 2022
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....
More Answers (1)
Cris LaPierre
on 6 Sep 2022
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 Comments
Cris LaPierre
on 6 Sep 2022
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])
See Also
Categories
Find more on Time Series Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!