Why I cannot exit the for cycle with the "z" counter?

1 次查看(过去 30 天)
I want that if a certain condition is met the iterations inside the cycle where the condition is met ends and the external for proceeds to the next case. The if condition is the "Cp(j,z)<=0" one and once it is met, I want that the code exits from the "z" for by going to the "j" for and increases it. The counter "z" is set on the vector omega_rpm correctly defined out of the concatenated for cycles.
Anyone can help?
for k=1:length(TSR)
k
for t=1:length(r_rif)
t
for j=1:length(v)
j
for z=1:length(omega_rpm)
z
omega(z)=omega_rpm(z)*(2*pi)/60;
for i=1:length(r)
i
a_new(j,:)=a_glauert(k,:);
a1_new(j,:)=a1_glauert(k,:);
a_old(j,:)=zeros(1,length(r));
a1_old(j,:)=zeros(1,length(r));
sigma(i)=chord_dim(k,t)*Nb/(2*pi*r(i));
counter=0;
while (abs(a_new(j,i)-a_old(j,i))>toll || abs(a1_new(j,i)-a1_old(j,i))>toll) && counter<10000
if abs(a_new(j,i)-a_old(j,i))>toll
a_old(j,i) = eps*a_new(j,i) + (1-eps)*a_old(j,i);
end
if abs(a1_new(j,i)-a1_old(j,i))>toll
a1_old(j,i) = eps*a1_new(j,i) + (1-eps)*a1_old(j,i);
end
fi(j,i)=atan(((1-a_old(j,i))*v(j))/((1+a1_old(j,i))*omega(z)*r(i)));
W(j,i)=((1-a_old(j,i))*v(j))/sin(fi(j,i));
f(j,i)=Nb*(R-r(i))/(2*r(i)*sin(fi(j,i)));
F(j,i)=2/pi*acos(exp(-f(j,i)));
Re(j,i)=ro_air*chord_dim(k,t)*W(j,i)/mu_air;
B(j,i) = fi(j,i) - Bc(k,t);
[CL_vect, CD_vect, B_vect]=polars_offdesign(Re(j,i),r(i),root,primary,tip,profile_rt,profile_p,profile_t);
[CL(j,i),CD(j,i),error(j,i)]=beta_interp(CL_vect,CD_vect,B_vect,B(j,i));
if error(j,i)==1
check=error(j,i);
lambda_error=TSR(k)
r_rif_error=r_rif(t)
v_error=v(j)
omega_error=omega(z)*60/(2*pi)
r_error=r(i)
return
end
if a_old(j,i)<0.4
a_new(j,i)=sigma(i)*W(j,i)*(CL(j,i)/tan(fi(j,i))+CD(j,i))/(4*v(j)*F(j,i));
a1_new(j,i)=sigma(i)*W(j,i)*(CL(j,i)-CD(j,i)/tan(fi(j,i)))/(4*omega(z)*r(i)*F(j,i));
elseif a_old(j,i)>0.4
Cx0=2;
a_new(j,i)=(0.5*Nb*W(j,i)^2*chord_dim(k,t)*(CL(j,i)*cos(fi(j,i))+CD(j,i)*sin(fi(j,i)))/(pi*r(i)*F(j,i)*v(j)^2)-Cx0+4*(sqrt(Cx0)-1))/(4*(sqrt(Cx0)-1));
a1_new(j,i)=(0.5*Nb*W(j,i)^2*chord_dim(k,t)*(CL(j,i)*cos(fi(j,i))-CD(j,i)*sin(fi(j,i))))/((1-a_new(j,i))*4*pi*r(i)^2*omega(z)*v(j)*F(j,i));
end
counter=counter+1;
end
a(j,i)=a_new(j,i);
a1(j,i)=a1_new(j,i);
dFt(j,i)=0.5*ro_air*W(j,i)^2.*chord_dim(k,t)*(CL(j,i)*sin(fi(j,i))-CD(j,i)*cos(fi(j,i)));
dFx(j,i)=0.5*ro_air*W(j,i)^2*chord_dim(k,t)*(CL(j,i)*cos(fi(j,i))+CD(j,i)*sin(fi(j,i)));
dM(j,i)=0.5*ro_air*W(j,i)^2*chord_dim(k,t)*(CL(j,i)*sin(fi(j,i))-CD(j,i)*cos(fi(j,i)))*r(i);
dCx(j,i)=sigma(i)*W(j,i)^2*(CL(j,i)*cos(fi(j,i))+CD(j,i)*sin(fi(j,i)))/v(j)^2;
dCp(j,i)=Nb*omega(z)/(pi*R^2*v(j)^3)*(chord_dim(k,t)*W(j,i)^2*(CL(j,i)*sin(fi(j,i))-CD(j,i)*cos(fi(j,i)))*r(i));
dPw(j,i)=ro_air*Nb*omega(z)/2*(chord_dim(k,t)*W(j,i)^2*(CL(j,i)*sin(fi(j,i))-CD(j,i).*cos(fi(j,i)))*r(i));
end
Cp(j,z)=trapz(r,dCp(j,:));
Pw(j,z)=trapz(r,dPw(j,:));
Cm(j,z)=Cp(j,z)/(omega(z)*R/v(j));
M(j,z)=Pw(j,z)/(omega(z));
Fx(j,z)=trapz(r,dFx(j,:));
Cx(j,z)=trapz(r,dCx(j,:));
if Cp(j,z)<=0
break;
end
end
end
end
end

回答(1 个)

the cyclist
the cyclist 2021-11-15
It looks your syntax is correct for what you are trying to do, and the if statement is correctly placed.
My best guess is that your condition
Cp(j,z)<=0
is not met when you expect it to be. You could put a debugging breakpoint at the line where you try to break out of the loop, and see if the code ever gets there.
  3 个评论
Emilio Pulli
Emilio Pulli 2021-11-15
编辑:Emilio Pulli 2021-11-15
Figured it out! I do not know how but I simply restart Matlab and now it works…I have never experienced something similar, it looked like a bug…

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by