Why the speed of for loop (drawnow) is much slower in R2025a than R2016a?

Why the speed of for loop (drawnow) is much slower in R2025a than R2016a?
%% Imaging reshape
for m=1:12
for n=1:12
img_index_x = (j) + (n-1)*step;
img_index_y = (i) + (m-1)*step;
if i <step && j <step %step/overscan
img_total(img_index_x,img_index_y)= temp_img(m,n);
else
current_value = img_total(img_index_x, img_index_y);
new_value = temp_img(m,n);
img_total(img_index_x, img_index_y) = max(current_value, new_value);
end
end
end
imagesc(img_total)
drawnow;
end
end

4 Comments

?? You do not have a loop that includes the drawnow? You do not have any timing statements? And you have two extra "end" statements?
That code is the partial code of mine.
So, please ignore the extra end statements :)
It looks like this is a chunk of code that used to be inside two outer loops. I see open scopes, missing variables, and magic numbers of unknown relevance. We have no idea what this does, whether it can be simplified, or why you're so sure that drawnow is the slowest part of four nested loops involving once-used graphics objects.
I'm guessing it's something like this, but I don't know what the intent would be, so I have to assume I'm probably wrong.
inpict = imread('cameraman.tif');
step = 16;
outpict = zeros(size(inpict),class(inpict));
sz = size(inpict,1:2);
for i = 1:step
for j = 1:step
for m = 1:sz(2)/step
for n = 1:sz(1)/step
idxx = (j) + (n-1)*step;
idxy = (i) + (m-1)*step;
if i < step && j < step %step/overscan
outpict(idxx,idxy) = inpict(m,n);
else
current_value = outpict(idxx,idxy);
new_value = inpict(m,n);
outpict(idxx, idxy) = max(current_value, new_value);
end
end
end
imagesc(outpict);
drawnow;
end
end
@Do Hyeon, you know that images are referenced by img_total(row, column), which is img_total(y, x), NOT img_total(x, y), right? Evidently not, because your x is the first coordinate. For a square image it doesn't matter, but just be careful because for a typical rectangular image, it does matter.

Sign in to comment.

Answers (1)

What is your default figure window style (which you can get with the following command)?
get(groot, "defaultFigureWindowStyle")
If, for example, this is "normal" and not "docked", it could be that you are getting a lot more overhead from opening multiple figure windows in R2025a than in prior releases. The default value for this is "docked", but maybe you changed it?

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products

Release

R2025a

Asked:

on 3 Aug 2025

Commented:

on 4 Aug 2025

Community Treasure Hunt

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

Start Hunting!