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
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] );
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-');
plot(x1, y1, x2, y2, ... xn, yn)
您可以像这样使用plot()将多个x / y坐标对同时放入一个绘图中。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.