duration for image plotting increases with every iteration

1 view (last 30 days)
Dear Forum,
I am running a loop which calculates the same portion of a 2d-array/matrix (all) every cycle. Every iteration the time of the iteration cycle increases. I traced the problem to the drawing of the matrix Both arrays (all (500x500) and portion (100x100)) are preallocated before the loop. The image is not redrawn by calling figure every time, but by using a handle, which is about 4times faster.
Does anybody know why it is taking longer every iteration? After about 1000 iterations it takes about 1 second longer than in the beginning of the loop. Or could it be that 'drawnow' is the culprit? Maybe my computer is just too slow? (Win XP, 3GB RAM and 2x3.5Ghz Dualcore)
Here is a part of one iteration cycle (the update step for portion is excluded b/c it is too large):
all = zeros(500,500);
hbg=image(all);
portion = zeros(100,100);
for t=1:1000
portion=update(portion);
all(px1:px2,py1:py2) = portion;
tapplyi=tic;
set(hbg,'CData',all);
drawnow;
tapply(loop)=toc(tapplyi);
end
I am very surprised by this behavior. Maybe someone else came across it before? Thank you in advance,
John

Answers (0)

Community Treasure Hunt

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

Start Hunting!