How do I write this c++ for loop statement in Matlab for loop?

조회 수: 13 (최근 30일)
Markas Tomasiunas
Markas Tomasiunas 2022년 10월 27일
답변: James Tursa 2022년 10월 27일

채택된 답변

James Tursa
James Tursa 2022년 10월 27일
E.g., using a while loop (changed max and min to maxx and minn):
x = j;
while( maxx >= minn && x <= m+r )
% body of loop code goes here
minn = minn + 1;
x = x + 1;
end

추가 답변 (1개)

Steven Lord
Steven Lord 2022년 10월 27일
You could write this as a while loop (though I'd advise you to change the variable names min and max as they already have meanings in MATLAB.)
You could also write this as a for loop that uses break to exit the loop when the condition is not satisfied; the upper limit of the loop variable would be m+r.
Depending on what the code is doing in the for loop body there may be other approaches to convert those operations into vectorized code that avoids the loop entirely, but without seeing the body and understanding what the purpose of the loop is we can't offer any more specific guidance on that approach.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by