multiple graph in one figure

Hello, I have data that are in results.txt, trying to achieve a graph similar to this one created on excel.
this is what I have done on matlab. I am not getting the result I need. on top of that I am sure there is an easier way to do that. it will be great if someone can help.
textFileName = ['results.txt'];
M = dlmread(textFileName);
for runs = 1:40
PS(runs)=M(runs,1);
RS(runs)=M(runs,2);
N(runs)=M(runs,3);
PSK(runs)=M(runs,4);
if PS(runs)==100
plot(N,PSK,'k')
grid on
elseif PS(runs)==250
plot(N,PSK,'b')
grid on
elseif PS(runs)==500
plot(N,PSK,'g')
grid on
elseif PS(runs)==750
plot(N,PSK,'r')
grid on
elseif PS(runs)==1000
plot(N,PSK,'c')
grid on
elseif PS(runs)==2500
plot(N,PSK,'m')
grid on
end
end
Thanks a lot.

1 Comment

Ayman El Hajjar's "Answer" moved here:
this is an extract of my data
100 8 10 33.33
100 8 25 57.14
100 8 50 52.09
100 8 100 50.52
250 13 10 27.26
250 13 100 52.85
250 13 200 52.45
250 13 250 50.43
500 18 10 0.00
500 18 25 46.15
500 18 500 49.49
750 22 10 16.67
750 22 25 54.55
750 22 500 50.97
750 22 750 49.91
1000 25 10 0.00
1000 25 25 55.61
1000 25 50 53.60
1000 25 750 49.66
1000 25 1000 54.01
2500 41 10 16.67
2500 41 25 48.48
2500 41 1000 49.54
2500 41 2500 49.17

Sign in to comment.

Answers (1)

Take a look at the function hold
Create some data
x = 1:10
y1 = 2*x+3
y2 = 3*x-4
plot(x,y1,'mo-') ;
hold on
plot(x,y2,'rs:') ;
hold off

5 Comments

or in one go:
plot(x,y1,'mo-',x,y2,'rs:')
Thanks for your answer.
I am aware of both hold on, off and plot(x,y1,'mo-',x,y2,'rs:') however what I am looking for is different.
How specifically is what you're looking for different than the behavior you receive with HOLD or plotting multiple lines in one PLOT call?
I have tried this before, it is not what I am looking for. If you notice I did not say it is wrong, I said what I am looking for is different.
textFileName = ['results.txt'];
M = dlmread(textFileName);
for runs = 1:40
%%Create a text file name, and read the file.
PS(runs)=M(runs,1);
RS(runs)=M(runs,2);
N(runs)=M(runs,3);
PSK(runs)=M(runs,4);
if PS(runs)==100
plot(N,PSK,'mo-') ;
grid on
hold on
elseif PS(runs)==250
plot(N,PSK,'b')
hold on
grid on
elseif PS(runs)==500
plot(N,PSK,'g')
hold on
grid on
elseif PS(runs)==750
plot(N,PSK,'r')
hold on
grid on
elseif PS(runs)==1000
plot(N,PSK,'rs:')
hold on
grid on
elseif PS(runs)==2500
plot(N,PSK,'mo-') ;
hold off
grid on
end
end
obviously I am missing something , but I am not sure where.

Sign in to comment.

Categories

Asked:

on 8 Jan 2016

Commented:

on 8 Jan 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!