0

suppose i have X={0,5.4,6.18,6.81,6.85,6.95,6.96,7.20,7.51} and

Y={0,4.84,5.52,6.00,6.12,6.21,6.23,6.34,6.61}.please help me to plot two lines

with these points in one single graph using MATLAB.Thanks

ranadhir
  • 21
  • 1
  • 1
  • 6

3 Answers3

7

It's confusing that you've called these X and Y. Assuming that they are actually two lines with linearly-increasing x-coordinates, you have some options. The simple way is to use hold:

plot(X);
hold on;
plot(Y);
hold off;

The other way is to combine them into a matrix. Provided they are the same length (and assuming column vectors):

plot( [X Y] );

But more fundamentally, you have shown your data as a cell array instead of a vector. You should convert these to vectors first. You can use cell2mat for this:

Xv = cell2mat(X)';
Yv = cell2mat(Y)';
plot( [Xv Yv] );
paddy
  • 60,864
  • 6
  • 61
  • 103
  • thanks but i want those points to be marked in different colour..how to do this.thanks – ranadhir Jun 06 '13 at 04:29
  • points should me marked and the lines should be in differnt colour..how can i do this? – ranadhir Jun 06 '13 at 04:34
  • plot(X); hold on; plot(Y); hold off; this program is working for me but i want those points to be marked in different colour and lines should be in differnt colour.thanks – ranadhir Jun 06 '13 at 04:36
  • You will need to read up on the plot function: `help plot` or `doc plot`. To use the plot colours, you'll have to use my first method where you plot one line at a time. If that's not powerful enough for you, you will need to modify the colours inside the figure, which is beyond the scope of this particular question. – paddy Jun 06 '13 at 04:37
3

You can also do:

x_axis_X = 1:length(X);
y_axis_Y = 1:length(Y);

figure;plot(x_axis_X, X,'o-', y_axis_Y, Y, 'x-');
fatihk
  • 7,789
  • 1
  • 26
  • 48
1

plot(x1, y1, x2, y2, ... xn, yn)

You can use plot() like so to put as many x/y coord pairs into a single plot simultaneously.

chossenger
  • 613
  • 6
  • 15
Melody
  • 21
  • 1