Search code examples
matlabgraphplotlinestyle

Matlab graph linetype


I wrote the code below to plot 3 normal distributions with diferent line styles.

x = 20:0.0001:30;
m1 = 30;
s1 = 5;
pdfNormal_1 = normpdf(x, m1, s1);
m2 = 15;
s2 = 2;
pdfNormal_2 = normpdf(x, m2, s2);
m3 = 18;
s3 = 3;
pdfNormal_3 = normpdf(x, m3, s3);
set(gcf,'color','w');

g=findobj(gca,'Type','patch');
% set(g(1),'FaceColor',[0 .5 .5],'EdgeColor','w')
% set(g(2),'FaceColor',[0 1 1],'EdgeColor','w')
% set(g(3),'FaceColor',[0 1 1],'EdgeColor','w')
set(gca,'Fontsize',12,'Fontname','euclid')
xlabel(' ') %título eixo xx
hold off;

%plot(x, pdfNormal_1, x, pdfNormal_2, x, pdfNormal_3);
plot(x,pdfNormal_1,'-')
plot(x,pdfNormal_2,':')
plot(x,pdfNormal_3,'--')

But it doesnt work. Could someone give a little help? Regards


Solution

  • Since you entered hold off before, you need hold on after the first plot. Otherwise, your plots will be replaced.

    plot(x,pdfNormal_1,'-'); hold on;
    plot(x,pdfNormal_2,':')
    plot(x,pdfNormal_3,'--')