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
  1 件のコメント
Junway
Junway 2021 年 3 月 18 日
I got it thanks

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by