Faster way to update a plot?

5 次查看(过去 30 天)
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!

采纳的回答

Chad Greene
Chad Greene 2016-1-3
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 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by