Showing multiple line in graph
Afficher commentaires plus anciens
I am execute an output in order to show 15 curve all together in a single graph. However, my commad only manage to execute a graph with a single line.
My coding and the output are shown below.
m=input('Enter the mass of hydrogen gas in unit of kg= ');
if m<0
disp('Invalid input.Please re-enter again the value')
end
%Molecular weight of H2=2.0g/mol
n=(m/2)*1000;
%Pressure of the gas(bar)
P=[1:50];
%Gas constant(L.bar/K.mol)
R=8.314*10^-2;
%Volume of the gas in each temperature range(L)
V1=303.15*n./P;
V2=308.15*n./P;
V3=313.15*n./P;
V4=318.15*n./P;
V5=323.15*n./P;
V6=328.15*n./P;
V7=333.15*n./P;
V8=338.15*n./P;
V9=343.15*n./P;
V10=348.15*n./P;
V11=353.15*n./P;
V12=358.15*n./P;
V13=363.15*n./P;
V14=368.15*n./P;
V15=373.15*n./P;
V=[V1;V2;V3;V4;V5;V6;V7;V8;V9;V10;V12;V12;V13;V14;V15];
V=V';
%%
%Linetype,PointType and Colour
linetype={'-',':','-.','--','-',':','-.','--','-',':','-.','--','-',':','-.'};
pointtype={'.','+','*','s','d','.','+','*','s','d','.','+','*','s','d'};
color={'b','g','r','c','m','y','k','w','b','g','r','c','m','w','g'};
%%
%Plotting the graph
for k=1:15;
plot(V(:,k),P,'color',color{k},'linestyle',linetype{k},'marker',pointtype{k});
end
title('Isoterms Profile of Hydrogen Gas');
xlabel('Volume/m3');
ylabel('Pressure/bar')
legend('30degC','35degC','40degC','45degC','50degC','55degC','60degC','65degC','70degC','75degC','80degC','85degC','90degC','95degC','100degC');
grid on;

Any additional command should I added or corrected?
Réponses (1)
Ameer Hamza
le 23 Mai 2020
Modifié(e) : Ameer Hamza
le 23 Mai 2020
You need to hold() the axes object.
ax = axes(); % add these two lines
hold(ax);
for k=1:15
plot(V(:,k),P,'color',color{k},'linestyle',linetype{k},'marker',pointtype{k});
end
or a crude but easier to understand form
hold on
for k=1:15
plot(V(:,k),P,'color',color{k},'linestyle',linetype{k},'marker',pointtype{k});
end
Catégories
En savoir plus sur Line Plots dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!