reduce running time of for loop

2 次查看(过去 30 天)
Jason
Jason 2016-3-1
回答: Jan 2016-3-1
Assume I have a code as below, how do we rewrite, so we can great reduce running time?
for i = 1: 500
% something to do
end
  1 个评论
KSSV
KSSV 2016-3-1
avoiding loop will reduce time. It depends on what is that something to do ?

请先登录,再进行评论。

回答(2 个)

sakshi ahuja
sakshi ahuja 2016-3-1
Function can be formed and relate this to your main work i.e., something u have to do, this will reduce your running time.

Jan
Jan 2016-3-1
There is no magic command to increase the speed like:
superspeedFor i = 1: 500
% something to do
end
As said before: You have to accelerate "something to do". If you can vectorize this part, the loop can be omitted, which is much faster in many situations.

类别

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