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,
No products are associated with this question.
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()
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).
6 Comments
Direct link to this comment:
http://www.mathworks.es/matlabcentral/answers/45089#comment_92705
Please review the guide to tags and retag this; see http://www.mathworks.co.uk/matlabcentral/answers/43073-a-guide-to-tags
Direct link to this comment:
http://www.mathworks.es/matlabcentral/answers/45089#comment_92706
You haven't posted the relevant info.
What are you specifically doing inside the loop, what type of inputs, size you have, have you preallocated?
W/o this info is hard to say.
Direct link to this comment:
http://www.mathworks.es/matlabcentral/answers/45089#comment_92759
I check if the value is correct or not and according the value in the cell i decide how to update the cell. The update is: to add or Substract to current value.
Direct link to this comment:
http://www.mathworks.es/matlabcentral/answers/45089#comment_92761
Please post the actual and complete code...
Direct link to this comment:
http://www.mathworks.es/matlabcentral/answers/45089#comment_92864
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.
Direct link to this comment:
http://www.mathworks.es/matlabcentral/answers/45089#comment_94123
Please review the guide to tag and retag this question; see http://www.mathworks.co.uk/matlabcentral/answers/43073-a-guide-to-tags