How I can stop this code with the bukle 'WHILE'?

1 次查看(过去 30 天)
I have a problems to stop the buckle while, the condition RK1>RK2 works.But the buckle while, I dont know what is wrong in the code because its not stop (is running all time)
thanks!
function lanzar_2(name)
filename= strcat(num2str(name));
runCommand=strcat('abaqus job=',filename);
[runStatus,runCmdout]=dos(runCommand);
pause(20);
% Rk2=0;
while 1
pause(5)
[Rk,XL41L400,F1]=Lecturas_abaqus(name) %Lectura del archivo STA
for i=2:length(F1)
RK2=F1(i,1);
RK1=F1(i-1);
if RK1>RK2
killCommand=strcat('abaqus job=',filename,32,'terminate');
[killStatus,killCmdout]=dos(killCommand);
break
end
end
end
end

采纳的回答

Yazan
Yazan 2021-7-12
When the condition RK1>RK2 becomes satisfied, the code breaks the for loop and returns the while loop, which is always satisfied as your condition is while 1. If you require your code to break from the for and while loops when the condition is satisfied, you can use the following:
function lanzar_2(name)
filename= strcat(num2str(name));
runCommand=strcat('abaqus job=',filename);
[runStatus,runCmdout]=dos(runCommand);
pause(20);
% Rk2=0;
var = 1;
while var
pause(5)
[Rk,XL41L400,F1]=Lecturas_abaqus(name) %Lectura del archivo STA
for i=2:length(F1)
RK2=F1(i,1);
RK1=F1(i-1);
if RK1>RK2
killCommand=strcat('abaqus job=',filename,32,'terminate');
[killStatus,killCmdout]=dos(killCommand);
var = 0;
break
end
end
end
end

更多回答(0 个)

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by