Storing values through a loop
2 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Paulo Silva
on 22 Apr 2011
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 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!