필터 지우기
필터 지우기

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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by