How do I write this c++ for loop statement in Matlab for loop?
Show older comments
Accepted Answer
More Answers (1)
Steven Lord
on 27 Oct 2022
1 vote
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.
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!