# Graphing multiple graphs in one figure

1 view (last 30 days)
Avery Herbert on 30 Jan 2020
Answered: Cameron B on 30 Jan 2020
We have this rankine cycle power plant and we just recently graphed the Cycle Efficiency and Net profit/loss as the boiler pressure varied from 5 to 15 MPa. Now we are required to change the turbine efficiency from .75 to .90 in 5 percent increments. Basically we are trying to graph make 4 different curves one for each different type of efficiency but we are struggling finding a way to find all four of those different curves and hold them. Below is the current code we are using to graph the cycle eff and net profit/loss.
BP=zeros(1,6);
for i=5:2:15
x=0.5*(i-5)+1;
BP(x)=i;
State2_value(x)=steam_properties('P',BP(x),'s',State1.s_l,'SI');
State3_value(x)=steam_properties('P',BP(x),'s',6.6797,'SI');
State4_value(x)=steam_properties('P',State1.P,'s',State3.s,'SI');
W_turbine(x)=State3_value(x).h-State4_value(x).h;
Q_boiler(x)=State3_value(x).h-State2_value(x).h;
efficiency(x)=1-abs(q_condenser/Q_boiler(x));
cost(x)=3/(10^6)*(0.9478)*(20*10^3)*(3600)*(365)*(24)*(1/efficiency(x));
net1(x)=sales-cost(x);
end
figure
subplot(2,1,1);
plot(BP,efficiency,'LineWidth',2);
title('Boiler Pressure Dependency');
xlabel('Boiler Pressure (MPa)');
ylabel('Cycle Efficiency');
axis([5 15,0.35 0.45]);
subplot(2,1,2);
plot(BP,net1,'LineWidth',2);
title('Boiler Pressure Dependency');
xlabel('Boiler Pressure (MPa)');
ylabel('Net Profit/Loss (\$)');
axis([5 15,-6e5 4e5]);

#### 1 Comment

Avery Herbert on 30 Jan 2020
We figure we need to make a for loop inside of a for loop but we do not know how to hold on to each different curve in order to put them all on one graph.

Cameron B on 30 Jan 2020
%Use hold on and hold off
clear
clc
xx=transpose(1:10);
hold on
for hh = 1:6
randvec(:,hh) = hh*xx.^2;
plot(xx,randvec(:,hh))
legendvec{hh} = sprintf('graph # %s',string(hh));
end
hold off
legend(legendvec,'Location','northwest')