フィルターのクリア

Storing values through a loop

2 ビュー (過去 30 日間)
Rudy
Rudy 2011 年 4 月 22 日
I wrote this program to store values in a loop and then plot them but I keep getting an error "In an assignment A(I) = B, the number of elements in B and I must be the same." for B(i),S(i) and B(i). Any ideas?
Ks=75; um=1.5; a=0.013; Si=100; Bi=10; D0=0.02; DD=0.02; Dmax=1.2; t=1;
Dm=D0:DD:Dmax;
for i= 1:length(Dm - 1) %it stops when D>Dmax %in W
B(i)=Bi;
S(i)=Si;
Y=0;
while 1%in Z
u=(um*S(i)/(Ks+S(i)));
if (abs(u-D(i))<=0.001)
B0(i)=D(i)*B(i);
D(i)=D(i)+DD;
break
%return from the while loop
else
Y=Y+1;
if Y>50
B0(i)=D(i)*B(i);
D(i)=D(i)+DD;
break
%return from the while loop
else
Bd=((u*B(i))-(D*B(i)))*t;
Sd=((Si*D(i))-(S(i)*D(i))-(u*B(i)*a))*t;
B(i)= B(i)+Bd;
S(i)= S(i)+Sd;
D(i)= D(i)+DD;
end
end
end
end
plot(D,B0,D,B,D,S)
  3 件のコメント
Paulo Silva
Paulo Silva 2011 年 4 月 22 日
I tested with D=0*Dm and it gives the error you talk about
Rudy
Rudy 2011 年 4 月 22 日
Initial D is 0.02, forgot to put D(i)=D0;

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

回答 (1 件)

Paulo Silva
Paulo Silva 2011 年 4 月 22 日
Bd size is [1 60] and B is [1 60] so you cant store more than one Bd value inside B, please consider something like this
B(i,:)= Bd; %don't forget to pre-allocate the arrays

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by