How can i solve "Index exceed the number of array problem(1)

2 次查看(过去 30 天)
t=0:0.1:800;
n=800;
Nddotin=500;
Nddotpen=8.9;
Nddotdep=Nddotin*nfilt;
Nddotsur=Nddotdep*(1-nanti);
for i=1:n+1
Nddotexi(1)=166;
Nddotexi(i+1)=((-1/t(i+1)-t(i))+r-fent+((1/(t(i+1)-t(i)))*(1/(t(i+1)-t(i))-2*(r-fent)+((4*r)/Nddotmax)*(Nddotexi(i)+Nddotsur(i+1)-Nddotsur(i)))+(r-fent)^2)^(0.5))/(2*r/Nddotmax);
Nddotent=fdotent*vmed*Nddotexi(i+1);
Nddotout=Nddotent+Nddotpen;
end
figure(1)
plot(t,Nddotout,'r*',t,Nddotent,'k*',t,Nddotpen,'g*');
xlable=('time'); ylabel=('Bioaerosol');
hold on; grid on;
%The bold sentence is the problem how can i solve that
  3 个评论
주선 문
주선 문 2022-8-23
clc;clear all;
p=2.7;a2=0.002;L=0.015;FA=0.35;MA=10;df=3*10^(-6);W=25*10^(-3); %filter2
Pe=df*L/W^2; Fk=(4*a2-(a2)^2-3)/4-(log(a2))/2;
r=0.0012; fdotent = 3*10^(-10); vmed= 1/(10*(1-a2));Cddotdep=0;%Cin=0
fent=fdotent*vmed;
ad=0;% ad=(Cddotdep*t)*(p*W);
a=a2+ad;
S=(4*L*a)/pi*df; Nddotmax=1.15*10^(7);
nanti=0.5; nfilt=0.5;
n=799;
Nddotin=500;
Nddotpen=8.9;
Nddotdep=Nddotin*nfilt;
Nddotsur=Nddotdep*(1-nanti);
for i=1:n+1
Nddotexi(1)=166;
Nddotexi(i+1)=((-1/0.1)+r-fent+((1/0.1)*(1/0.1)-2*(r-fent)+((4*r)/Nddotmax)*(Nddotexi(i)+Nddotsur(i+1)-Nddotsur(i)))+(r-fent)^2)^(0.5)/(2*r/Nddotmax);
Nddotent=fdotent*vmed*Nddotexi(i+1);
Nddotout=Nddotent+Nddotpen;
end
figure(1)
plot(t,Nddotout,'r*',t,Nddotent,'k*',t,Nddotpen,'g*');
xlable=('time'); ylabel=('Bioaerosol');
hold on; grid on;

请先登录,再进行评论。

采纳的回答

Chunru
Chunru 2022-8-23
Not sure what you want to do with the code without background info. It seems that you need to specify "Nddotsur" as a vector.
p=2.7;a2=0.002;L=0.015;FA=0.35;MA=10;df=3*10^(-6);W=25*10^(-3); %filter2
Pe=df*L/W^2; Fk=(4*a2-(a2)^2-3)/4-(log(a2))/2;
r=0.0012; fdotent = 3*10^(-10); vmed= 1/(10*(1-a2));Cddotdep=0;%Cin=0
fent=fdotent*vmed;
ad=0;% ad=(Cddotdep*t)*(p*W);
a=a2+ad;
S=(4*L*a)/pi*df; Nddotmax=1.15*10^(7);
nanti=0.5; nfilt=0.5;
n=799;
Nddotin=500;
Nddotpen=8.9;
Nddotdep=Nddotin*nfilt;
Nddotsur=Nddotdep*(1-nanti);
% Initialize Nddotexi
Nddotexi = zeros(n+1, 1);
Nddotexi(1)=166;
for i=1:n % not n+1
%Nddotexi(i+1)=((-1/0.1)+r-fent+((1/0.1)*(1/0.1)-2*(r-fent)+((4*r)/Nddotmax)*(Nddotexi(i)+Nddotsur(i+1)-Nddotsur(i)))+(r-fent)^2)^(0.5)/(2*r/Nddotmax);
% Note that Nddotsur is not a vector
Nddotexi(i+1)=((-1/0.1)+r-fent+((1/0.1)*(1/0.1)-2*(r-fent)+ ...
((4*r)/Nddotmax)*(Nddotexi(i)+Nddotsur(i+1)-Nddotsur(i)))+(r-fent)^2)^(0.5)/(2*r/Nddotmax);
Nddotent=fdotent*vmed*Nddotexi(i+1);
Nddotout=Nddotent+Nddotpen;
end
Index exceeds the number of array elements. Index must not exceed 1.
figure(1)
plot(t,Nddotout,'r*',t,Nddotent,'k*',t,Nddotpen,'g*');
xlable=('time'); ylabel=('Bioaerosol');
hold on; grid on;
  1 个评论
주선 문
주선 문 2022-8-23
编辑:주선 문 2022-8-23
a2=0.002;%p=2.7;L=0.015;FA=0.35;MA=10;df=3*10^(-6);W=25*10^(-3); %filter2
%Pe=df*L/W^2; Fk=(4*a2-(a2)^2-3)/4-(log(a2))/2;
r=0.0012; fdotent = 3*10^(-10); vmed= 1/(10*(1-a2));Cddotdep=0;%Cin=0
fent=fdotent*vmed;
ad=0;% ad=(Cddotdep*t)*(p*W);a=a2+ad;S=(4*L*a)/pi*df;
Nddotmax=1.15*10^(7);
nanti=0.5; nfilt=0.5;
n=input('input:');
Nddotin=500;
Nddotpen=8.9;
Nddotdep=Nddotin*nfilt;
Nddotsur=Nddotdep*(1-nanti);
% Initialize Nddotexi
Nddotexi = zeros(n+1, 1);
Nddotsur = zeros(n+1, 1);
Nddotexi(1)=166;
for i=1:n
Nddotexi(i+1)=((-1/0.1)+r-fent+((1/0.1)*(1/0.1)-2*(r-fent)+ ...
((4*r)/Nddotmax)*(Nddotexi(i)+Nddotsur(i+1)-Nddotsur(i)))+(r-fent)^2)^(0.5)/(2*r/Nddotmax);
Nddotent=fdotent*vmed*Nddotexi(i+1);
Nddotout=Nddotent+Nddotpen;
end
figure(1)
plot(t,Nddotout,'r*',t,Nddotent,'k*',t,Nddotpen,'g*');
xlable=('time'); ylabel=('Bioaerosol');
hold on; grid on;
Nddotout is Nddotent+Nddotpen
Nddotout is not change

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by