Issue with vectors being the same length

2 ビュー (過去 30 日間)
Rebekah Kuehl
Rebekah Kuehl 2021 年 1 月 16 日
コメント済み: Walter Roberson 2021 年 1 月 16 日
My code seems to be having a problem with plotting. I've even tried using linspace to 'fix' xx and Vz1 but that didn't seem to work. Any suggestions would be much appreciated
Error message:
Error using plot
Vectors must be the same length.
Error in Example2 (line 244)
plot(xx,Vz1,'b-','LineWidth',2);
Lines of code to fix:
Defining xx:
xa = 0;
xb = 20;
xc = 40;
x1 = linspace(xa,xb,nn)';
x2 = linspace(xb,xc,nn)';
xx=[x1;x2];
Defining Vz1:
Vz1 = 0*ones(nn,1);
Vz2 = 0*ones(nn,1);
Vz=[Vz1;Vz2];

採用された回答

Walter Roberson
Walter Roberson 2021 年 1 月 16 日
x1 = linspace(xa,xb,nn)';
x2 = linspace(xb,xc,nn)';
xx=[x1;x2];
so xx is going to be (nn x 1) + (nn x 1) = 2*nn x 1.
Vz1 = 0*ones(nn,1);
so Vz1 is going to be nn x 1
plot(xx,Vz1,'b-','LineWidth',2);
xx is 2*nn x 1, Vz1 is nn x 1. Different sizes.
  2 件のコメント
Rebekah Kuehl
Rebekah Kuehl 2021 年 1 月 16 日
Thanks for explaining it!
how would you recommend that I fix this?
Walter Roberson
Walter Roberson 2021 年 1 月 16 日
plot(x1,Vz1,'b-','LineWidth',2);
or
plot(xx,Vz,'b-','LineWidth',2);

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by