Azzera filtri
Azzera filtri

Faster way to update a plot?

5 visualizzazioni (ultimi 30 giorni)
Leo Müller
Leo Müller il 18 Nov 2015
Risposto: Chad Greene il 3 Gen 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!

Risposta accettata

Chad Greene
Chad Greene il 3 Gen 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.

Più risposte (0)

Categorie

Scopri di più su Graphics Performance in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by