three difference vectors and plots

조회 수: 2 (최근 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