2

I am trying to plot 3 graph within a single graph with x=1 to 10 and Y as power of 10 using semilogy but only one(the last one) graph is plotted and the remaining remains unploted.

semilogy(x,getval4(x,5),'-og');
semilogy(x,getval4(x,10),'--Xb');
semilogy(x,getval4(x,20),'--r');

Only semilogy(x,getval4(x,20),'--r');is plotted .I am new to mat lab so please sujjest me a way to plot all the three graphs.Also,I would like to have a grid too

Abx
  • 2,852
  • 4
  • 30
  • 50

2 Answers2

3

You need to do

semilogy(x,getval4(x,5),'-og');
hold on ;
semilogy(x,getval4(x,10),'--Xb');
semilogy(x,getval4(x,20),'--r');

(note the hold on after the first semilogy, not before)

Shawn
  • 593
  • 4
  • 12
2

Another option:

plot(x,getval4(x,5),'-og');
hold on ;
plot(x,getval4(x,10),'--Xb');
plot(x,getval4(x,20),'--r');
set(gca,'yscale','log')
shamalaia
  • 2,282
  • 3
  • 23
  • 35