Error using Plot, Vectors must be the same length

100 ビュー (過去 30 日間)
NERANJEN S
NERANJEN S 2021 年 8 月 1 日
コメント済み: Scott MacKenzie 2021 年 8 月 1 日
>> Height = [0;3;6;9;12;15];
>> for i = 1:5
subplot(1,5,i)
plot([0;v(:,i)], Height);
ylabel('Height of the structure (m)','FontSize',12);
title(['Mode Shape ',num2str(i)],'FontSize',18)
end
How to rectify this?!
  2 件のコメント
Chunru
Chunru 2021 年 8 月 1 日
what is "v" in your code?
NERANJEN S
NERANJEN S 2021 年 8 月 1 日
@Chunru Here, v is a 3x3 matrix

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

採用された回答

Scott MacKenzie
Scott MacKenzie 2021 年 8 月 1 日
編集済み: Scott MacKenzie 2021 年 8 月 1 日
Your vector Height has six elements, with 0 as the first element. Given this, your apparent effort to plot v vs. Height is causing the error because [0; v] and Height need to be the same length. The code below achieves this with test data for v (replace as necessary) The code also sets to length(Height) the number of iterations in the for-loop and the number of subplots (adjust as necessary).
% data given in question (6x1 vector)
Height = [0;3;6;9;12;15];
% test data (replace as needed)
v = rand(length(Height)-1,10);
for i = 1:length(Height)
subplot(1,length(Height),i)
plot([0; v(:,i)], Height);
ylabel('Height of the structure (m)','FontSize',12);
title(['Mode Shape ',num2str(i)],'FontSize',10)
end
  3 件のコメント
NERANJEN S
NERANJEN S 2021 年 8 月 1 日
Ok sir! Now understood! Thanks a lot!
Scott MacKenzie
Scott MacKenzie 2021 年 8 月 1 日
You're welcome. Good luck.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by