Faster way to update a plot?
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Leo Müller
el 18 de Nov. de 2015
Respondida: Chad Greene
el 3 de En. de 2016
Hello dear community.
I have the following problem:
My program creates a two different arrays (vectors of different lengths) in each step of a for-loop. Right now I am plotting these two vectors within the loop which makes it update each time the loop is completed. Unfortunately the plotting seems to have a great impact on the speed of my program. I would like to ask for advice to speed up my loop.
Thank you for your help!
0 comentarios
Respuesta aceptada
Chad Greene
el 3 de En. de 2016
Do you need to plot inside the loop? The best thing you can do is wait on plotting until after the loop. For example,
hold on
for x = 1:1000
plot(x,sind(x),'bo')
end
will take much longer than
x = 1:1000;
y = NaN(size(x));
for k = 1:length(x);
y(k) = sind(x(k));
end
plot(x,y,'bo')
If you can remove the loop entirely, that will be fastest:
x = 1:1000;
y = sind(x);
plot(x,y,'bo')
Experiment with the above. Put tic before a section and toc after to see how long it takes your computer to run a given section.
0 comentarios
Más respuestas (0)
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!