Index exceeds the number of array elements
이전 댓글 표시
clear
C1(1)= 10; %mol/L
V_tank = 1.0; %m^3
V1(1)= 0.0004167; %m^3/s
C_target(1) = 6; %mol/L
V2_stst = 0.0001278; %m^3/s
k= 2.5*(10^-5); %1/Ms
dt= 1; %s
t_max = 2; %h
i_max = floor(t_max*3600/dt);
n= zeros(1,10000);
C1(1) = C1(1) *1000; % mol/L to mol/m^3
C_target(1) = C_target(1) * 1000; % mol/L to mol/m^3
t = 0.0:dt:(i_max-1)*dt; %s
for i=1:1:i_max-1
V1(i+1)=V1(1);
C1(i+1)=C1(1);
n(i+1)=n(i)+(C1(i)*V1(i)-n(i)/V_tank*(V1(i)+V2_stst)-(k*V_tank*C_target(i)))*dt;
end
It says that there is an error in the line :
n(i+1)=n(i)+(C1(i)*V1(i)-n(i)/V_tank*(V1(i)+V2_stst)-(k*V_tank*C_target(i)))*dt;
After getting the error once, I included the line :
n= zeros(1,10000);
But it still says there is an error.
How do I fix this?
답변 (1개)
the cyclist
2021년 3월 21일
You have defined C_target as a scalar (i.e. a single value), but you try to access it in the for loop with
C_target(i)
so when i==2, you are trying to access an element that does not exist.
카테고리
도움말 센터 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!