Faster way to update a plot?

8 vues (au cours des 30 derniers jours)
Leo Müller
Leo Müller le 18 Nov 2015
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!

Réponse acceptée

Chad Greene
Chad Greene le 3 Jan 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.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Performance dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by