Improve calculation time with plots
1 次查看(过去 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!