Plotting error "Vectors must be the same length"

2 ビュー (過去 30 日間)
omar rakgha
omar rakgha 2022 年 3 月 31 日
コメント済み: omar rakgha 2022 年 3 月 31 日
Hi,
I am trying to plot each j output for y1 in a seperate subplot but i keep getting "Error using plot, Vectors must be the same length"
Can someone help, ive tried everything but nothing seems to fix this.
clc; clear all; format compact;close all
% Numerical Solution
A = 2; % m2
Kc = linspace(1,5,5); % m2/min
Ti = 0.1; % min
y2(1,[1 2 3 4 5]) = 2;
y1(1,[1 2 3 4 5]) = 0;
Ntime = 1000;
DeltaT = 50/Ntime;
t(1) = 0;
y2(1,[1 2 3 4 5]) = 2;
y1(1,[1 2 3 4 5]) = 0;
for j = 1:5
for n = 1:Ntime
y2(n+1,j) = y2(n,j)-((1/A)*(Kc(j)*y2(n,j)+Kc(j)*y1(n,j)/Ti)*DeltaT);
y1(n+1,j) = y1(n,j)+y2(n,j)*DeltaT;
t(n+1,j) = t(n)+DeltaT;
end
subplot(1,5,j)
plot(t,y1)
end

採用された回答

VBBV
VBBV 2022 年 3 月 31 日
t(n+1)=t(n)+DeltaT;
Change this line to above
  2 件のコメント
VBBV
VBBV 2022 年 3 月 31 日
subplot(5,1,j)
Do this for better display of graphs
omar rakgha
omar rakgha 2022 年 3 月 31 日
thank you so much!!!!!!!!!!!

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by