Plotting error "Vectors must be the same length"

2 views (last 30 days)
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

Accepted Answer

VBBV
VBBV on 31 Mar 2022
t(n+1)=t(n)+DeltaT;
Change this line to above

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!