MATLAB Answers

while loop performance improvement

조회 수: 2(최근 30일)
cglr 17 Nov 2019
Edited: cglr 18 Nov 2019
Hello everyone,
What is the alternative of while loop for the example:
rate = 2;
while (k <= period)
sum = sum + array(k,2);
k = k + rate;

  댓글 수: 0

로그인 to comment.

채택된 답변

Fabio Freschi
Fabio Freschi 17 Nov 2019
I don't know the starting value of k, assuming it is 1
idx = 1:rate:period
mysum = sum(array(idx,2)); % note that sum is the name of a matlab function

  댓글 수: 1

cglr 18 Nov 2019
Thank you.
maxDuration = 0;
while (k <= period)
if( myArray (k,2) > maxDuration)
maxDuration = myArray (k,2);
k = k + rate;
If I make it more complex with if statement like that, how can I use that idea ?

로그인 to comment.

More Answers (0)

이 질문에 답변하려면 로그인을(를) 수행하십시오.

Translated by