while loop performance improvement

1 次查看(过去 30 天)
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;
end
Thanks.

采纳的回答

Fabio Freschi
Fabio Freschi 2019-11-17
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
cglr 2019-11-18
编辑:cglr 2019-11-18
Thank you.
maxDuration = 0;
while (k <= period)
if( myArray (k,2) > maxDuration)
maxDuration = myArray (k,2);
end
k = k + rate;
end
If I make it more complex with if statement like that, how can I use that idea ?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Environment and Clutter 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by