drawnow() is a "show me what you have so-far" function.
It is inefficient to have the screen update after every graphics change -- and if you tried to do that you would end up with some oddities. For example if you are moving an object from one place to another, and you update after every change, then would you want a copy of the object to appear in the new place as well before being removed from the old place, or would you want the object to temporarily be in no-place because you removed it from view before making it visibile in the new location?
So you do not want to update the screen after every change.
If you do not update the screen until after all changes have been done, then you would not be able to do animation.
So when should the screen update? Well, MATLAB defines that the screen updates:
- when you pause(), the graphics system will finalize any internal updates and update the screen
- likewise when you call figure() -- regardless of whether you are creating a new figure or asking an existing figure to become the "current" figure, calling figure() triggers a screen update
- waitfor() or uiwait() trigger screen updates
- returning to the command line (either end of execution or because of keyboard() or for debugging purposes) triggers a screen update
- drawnow() also triggers a screen update, except if you used "drawnow limitrate", in which case
If it has been less than 50 milliseconds since
the last update, or if the graphics renderer is busy with the previous
change, then the new updates are discarded.
So do not think in terms of drawnow somehow taking action itself: just call drawnow() at each point that you want the screen to update.
I think your loop might look like
- generate new coordinates
- update an array of counters to increase the count at the (rounded) coordinates. Update the CData of an image() with the new array
- update the XData and YData associated with the cursor dot