Why plotting colocrbar slows down the performance of MATLAB
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ahmad Gad
el 22 de Dic. de 2020
Comentada: Ahmad Gad
el 4 de En. de 2021
Hello everyone. I have a question that I am not able to solve.
I have a cell array 'Temp' that defined the frames of a thermal video. Each cell defines an intensity image of the video. When I plot them using this:
tic
for i = 1:size(Temp,1)
imagesc(Temp{i});
drawnow;
end
toc
Elapsed time is 16.539161 seconds.
When I try to include the colorbar to get some unmerical idea about the thermal images, using the following code:
tic
for i = 1:size(Temp,1)
imagesc(Temp{i});
colorbar; % I just asked for the colorbar to be added
drawnow;
end
toc
Elapsed time is 79.288858 seconds.
Why this big change in the performance of the code when I add the colorbar? Can anyone explain or tell a workaround?
Thanks all and best,
Ahmad
2 comentarios
Subhadeep Koley
el 22 de Dic. de 2020
@Ahmad Gad You can call the colorbar function only once outside the for loop. No need call it iteratively.
Although, I'm not sure about your application, but by calling imagesc(Temp{i}) iteratively, you will only see the last frame of your video, as for every iteration the previous imagesc plot will be overwritten with the current one.
Respuesta aceptada
Walter Roberson
el 22 de Dic. de 2020
for K = 1 : 60; Temp{K} = rand(320,240); end
tic
fig = figure();
ax = axes(fig);
for i = 1:size(Temp,1)
imagesc(ax, Temp{i});
drawnow;
end
toc
tic
fig = figure();
ax = axes(fig);
for i = 1:size(Temp,1)
imagesc(ax, Temp{i});
colorbar(ax); % I just asked for the colorbar to be added
drawnow;
end
toc
Yup, colorbar added was a lot slower.
tic
fig = figure();
ax = axes(fig);
colorbar(ax); % I just asked for the colorbar to be added
hold(ax, 'on');
h = imagesc(ax, Temp{1});
for i = 2:size(Temp,1)
h.CData = Temp{i};
drawnow;
end
hold(ax, 'off')
toc
But being careful about using handles is faster.
Más respuestas (0)
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!