Storing values through a loop
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!