three difference vectors and plots

1 次查看(过去 30 天)
Junway
Junway 2021-3-17
评论: Junway 2021-3-18
I want to plot three difference vector in one figure.
this is sample data. I keep error "vectors must be the same length".
how should I change it?
x = [ 1, 2, 3, 4, 5]
x1 = [ 1.1, 2.2, 3.4, 4, 4.5]
x2 = [0.9, 1.9, 3, 3.9, 4.3]
y= [1, 2, 3, 4, 5];
y1=[2, 3, 4, 5, 6];
y2 = [1, 3, 6, 7, 8]
hold on
plot(x,y)
plot(x1,y1)
plot(x2,y2)
hold off

回答(1 个)

Steve Eddins
Steve Eddins 2021-3-18
I have copy-pasted your code below, exactly as entered in your question. It runs and produces the plot with no error. I suggest that you double-check your code carefully. If you still get an error, then copy your code from MATLAB directly into a comment here, along with the exact text of any error message, so that we can take a look.
x = [ 1, 2, 3, 4, 5]
x = 1×5
1 2 3 4 5
x1 = [ 1.1, 2.2, 3.4, 4, 4.5]
x1 = 1×5
1.1000 2.2000 3.4000 4.0000 4.5000
x2 = [0.9, 1.9, 3, 3.9, 4.3]
x2 = 1×5
0.9000 1.9000 3.0000 3.9000 4.3000
y= [1, 2, 3, 4, 5];
y1=[2, 3, 4, 5, 6];
y2 = [1, 3, 6, 7, 8]
y2 = 1×5
1 3 6 7 8
hold on
plot(x,y)
plot(x1,y1)
plot(x2,y2)
hold off

类别

Help CenterFile Exchange 中查找有关 Annotations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by