MATLAB: In an assignment A(I) = B, the number of elements in B and I must be the same.

forloop

I have a problem with my current Matlab code
if true
% code
end
if true
Nt=T/dt+1;
t=0:dt:T;
phi=zeros(Nt,1);
b=zeros(Nt,1);
f=zeros(Nt,1);
p(1)=3;
b(1)=10;
f(1)=l;
for i=1:Nt-1
b(i)=(12*pi(i))/(2*r)^2;
f(i)=l*p(i)^(3/2)/(2*r^2*((p(i)-1)^(1/2)));
p(i+1)=p(i)+dt*(p(i)-p(i)*((1-f/(sqrt(b*p(i))*x))*sinh(sqrt(b*p(i))*x)));
end
For p(i+1) Matlab keeps saying "In an assignment A(I) = B, the number of elements in B and I must be the same." Any ideas?

Best Answer

Nt=T/dt+1;
t=0:dt:T;
phi=zeros(Nt,1);
b=zeros(Nt,1);
f=zeros(Nt,1);
p(1)=3;
b(1)=10;
f(1)=l;
for i=1:Nt-1
b(i)=(12*p(i))/(2*r)^2;
f(i)=l*p(i)^(3/2)/(2*r^2*((p(i)-1)^(1/2)));
p(i+1)=p(i)+dt*(p(i)-p(i)*((1-f(i)/(sqrt(b*p(i))*x))*sinh(sqrt(b*p(i))*x)));
end