to speed up 'for' loop

1 次查看(过去 30 天)
hello,
i have a loop with the following format:
for n = 1:length(x)
if ....
.....
elseif ....
.......
end
end
I suspect that it takes too long and my program is stuck. the length of 'x' currently 1200 cells and it might vary. How can I speed this up?
thanks,
  5 个评论
Rick Rosson
Rick Rosson 2012-8-2
Please post the actual and complete code...
Michael Adelman
Michael Adelman 2012-8-3
Hello Rick,
I'm sorry but I really can't post the actual code. The loop as I described is very simple and do check for the value of the cell and then do a substitution or addition to the current value.

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2012-8-1
Processing 1200 items in an array would normally take too little time to measure meaningfully, unless the processing for each one takes a long time (in which case that is the problem rather than the for loop.)
I suggest you use the profiler to measure the performance. You could temporarily change the upper bound to something smaller than length(x)
You may wish to consider using waitbar()

更多回答(1 个)

Michael Adelman
Michael Adelman 2012-8-3
Hello Walter,
Thank you , using a profiler really gave me a lot of information that I wan't aware of it before.
I'll continue to analyze the code and then ask more specific questions.
waitbar() is not a good use for me, since the code must work in real time telemetry and no wait/delay are allowed (as little as possible).

类别

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