Updating plot in loop takes increasing amount of time
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    dleal
      
 el 5 de Mayo de 2022
  
    
    
    
    
    Comentada: dleal
      
 el 6 de Mayo de 2022
            When I update a plot within a loop, each iteration takes longer after a while. Is there a way to avoid the slowdown? See example below:
f = figure;
a = axes(f);
hold(a,"on")
% note: y is supposed to represent real-time data that I receive with some
% frequency. The full vector Y is not available right before plotting
y = randn(1,100000);
for jj = 1:numel(y)
    tt = tic;
    plot(a,jj,y(jj),'pg');
    drawnow;
    pause(0.02)
    toc(tt)
end
I understand the x and y arguments of the plot are getting larger. Is that the cause? After 6,000 iterations, it already takes three times as long as when the loop it started. Thank you
2 comentarios
Respuesta aceptada
Más respuestas (1)
  Matt J
      
      
 el 5 de Mayo de 2022
        
      Editada: Matt J
      
      
 el 5 de Mayo de 2022
  
      I understand the x and y arguments of the plot are getting larger. Is that the cause?
The arguments aren't getting larger, but the number of objects in the plot is getting larger and larger. You can reduce the overall time, though, if  the graph doesn't need to be redrawn as frequently.
Maybe update in sub-chunks of y:
f = figure;
a = axes(f);
hold(a,"on")
y = randn(1,100000);
for jj = reshape( 1:numel(y),1000,[]) %<--- loop over sub-chunks of length 1000
    tt = tic;
    plot(a,jj,y(jj),'pg');
    drawnow;
    pause(0.02)
    toc(tt)
end
Ver también
Categorías
				Más información sobre Graphics Performance 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!


