Borrar filtros
Borrar filtros

Improve calculation time with plots

2 visualizaciones (últimos 30 días)
Matt
Matt el 31 de Mzo. de 2015
Editada: Mike Garrity el 31 de Mzo. de 2015
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! :)

Respuestas (2)

Brendan Hamm
Brendan Hamm el 31 de Mzo. de 2015
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 comentario
Mike Garrity
Mike Garrity el 31 de Mzo. de 2015
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.

Iniciar sesión para comentar.


Matt
Matt el 31 de Mzo. de 2015
Thanks for your answer. I tried the ADDPOINTS function but it is much slower than just using the set function (I checked that with the TIC TOC combination.
  1 comentario
Mike Garrity
Mike Garrity el 31 de Mzo. de 2015
Editada: Mike Garrity el 31 de Mzo. de 2015
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?

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Performance en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by