Borrar filtros
Borrar filtros

Storing values through a loop

2 visualizaciones (últimos 30 días)
Rudy
Rudy el 22 de Abr. de 2011
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 comentarios
Paulo Silva
Paulo Silva el 22 de Abr. de 2011
I tested with D=0*Dm and it gives the error you talk about
Rudy
Rudy el 22 de Abr. de 2011
Initial D is 0.02, forgot to put D(i)=D0;

Iniciar sesión para comentar.

Respuestas (1)

Paulo Silva
Paulo Silva el 22 de Abr. de 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

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by