Improve calculation time with plots
조회 수: 5 (최근 30일)
이전 댓글 표시
Hello gentlemen,
I would like to improve the calculation time of my script (especially the plot part of it). In my script I am running a while loop in which I have the following type of commands (about 10 of them plotting on 10 different axes):
set(Hd1.plotspeed, 'Xdata', time(1:pos), 'Ydata', speed(1:pos));
This is displayed "in real time" by using the POS variable that only grows. The graphs don't only show the current position (of course), but as you noticed, they display the evolution from T=0.
I already moved the "plot" part outside the while loop, and only use these SET functions to update the graphs so I don't create them every iteration, but is there a way to improve this?
I thought about creating another loop inside my while loop which would only allow these SET functions to be accessed every 10 "pos" increment, but maybe there is a better solution?
Thanks! :)
댓글 수: 0
답변 (2개)
Brendan Hamm
2015년 3월 31일
I would suggest taking a look at the drawnow command.
docsearch Animating Line Graphs
This example should help you. (Note: In 2014b you probably want to remove the word 'update' which follows draw now.)
If you did want to consider plotting every tenth step, use an if statement with modulo 10 instead of another loop:
if ~mod(loopVar,10)
set(...)
end
댓글 수: 1
Mike Garrity
2015년 3월 31일
No, the 'drawnow update' is a deliberate choice there. It's basically doing what your if/mod is doing. It's only sending data to the graphics card if the card has finished with the previous chunk of data. You should also look at 'drawnow fillrate' in R2015a.
Matt
2015년 3월 31일
댓글 수: 1
Mike Garrity
2015년 3월 31일
편집: Mike Garrity
2015년 3월 31일
That's kind of surprising. Could you provide more details? For example,
- How big is your data?
- What datatypes are your arrays?
- What kind of machine are you on?
- What does 'opengl info' say?
- Does the profiler point at the set or the drawnow?
- Are you also using things like subplot or linkaxes?
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!