While loop to break out of for loop

조회 수: 3 (최근 30일)
jacob gandrup
jacob gandrup 2019년 3월 26일
답변: Raghunandan V 2019년 3월 26일
Hello matlab friends.
I want to create a while loop inside a for loop in order to break the loop if a specific value is exceeded.
In my case mBall illustrates positional data on the z-axis. So everytime the mBall reaches a height of 2 i want the code to break, and if not i want the code to continue.
I have tried to give it try, but i'm not sure what is going wrong. I hope you can help
pos={};
limit = 2;
for a= 1:size(output5,2)
a;
while (mBall(i,3)> limit)
if mBall(i,3) >= limit
break
if mBall(i,3) < limit
continue
end
end
end
pos{size(pos,2)+1} = find(0 < output5(:,a) & output5(:,a) < 1);
end

답변 (1개)

Raghunandan V
Raghunandan V 2019년 3월 26일
I would say yopu have to break using if condition. While command is used when you want a loop
pos={};
limit = 2;
for a= 1:size(output5,2)
a;
if (mBall(i,3)>= limit)
break;
end
pos{size(pos,2)+1} = find(0 < output5(:,a) & output5(:,a) < 1);
end

카테고리

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