Speed up plot in loop?

조회 수: 11 (최근 30일)
Leo Müller
Leo Müller 2015년 11월 18일
답변: Ronit 2025년 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!

답변 (1개)

Ronit
Ronit 2025년 5월 30일
Hello,
To speed up the code execution, following are a few suggestions which you can use:
  1. Instead of plotting during each iteration (which is slow), store the data in each loop and create the plot after the loop finishes.
  2. If you still need to update a plot inside the loop (e.g., for animation), use "drawnow limitrate" to reduce the frequency of GUI updates. This limits the redraw rate and prevents MATLAB from refreshing the figure on every single iteration.
Refer to the documentation page of the "drawnow" function for more details regarding "drawnow limitrate": https://www.mathworks.com/help/matlab/ref/drawnow.html
I hope this resolves your issue!
Thanks

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by