Вопрос

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

Это было полезно?

Решение 2

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-');

Другие советы

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] );

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top