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 CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by