How to use multiple break statments
3 次查看(过去 30 天)
显示 更早的评论
In the below code if any of the error goes below the limit the loop break. But I want to break the loop if all of the conditions errors are below the defined limits. How can I modify this piece of code.
for i = 1:100
if(sln2.Error<=1)
break
else
% Update weights
Ext.W22=beta*Ext.W22;
Ext.W22List(i) = Ext.W22;
end
%% Convergance Check sub 2
sln3.Error=max(abs(Ext.P_gen_scaling-Ext.P_gen_scaling_3));
SLN3(i)=sln3;
if(sln3.Error<=0.1)
break
else
end
4 个评论
采纳的回答
David Hill
2021-7-14
for i = 1:100
if ~(sln2.Error<=1)
Ext.W22=beta*Ext.W22;
Ext.W22List(i) = Ext.W22;
end
sln3.Error=max(abs(Ext.P_gen_scaling-Ext.P_gen_scaling_3));
SLN3(i)=sln3;
if (sln3.Error<=0.1)&&(sln2.Error<=1)
break;
end
end
更多回答(1 个)
Jan
2021-7-14
for i = 1:100
Ext.W22 = beta * Ext.W22;
Ext.W22List(i) = Ext.W22;
%% Convergance Check sub 2
sln3.Error = max(abs(Ext.P_gen_scaling - Ext.P_gen_scaling_3));
SLN3(i) = sln3;
if (sln3.Error <= 0.1) && (sln2.Error <= 1)
break
end
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!