I'd like to create auto-scrolling plots in which data scrolls by, automatically, as it gets collected (from a DAQ). Before worrying about adding data I wanted to first check how plots behave with a pre-defined data vector where I adjust the x-limits to simulate scrolling. Just to clarify, I don't intend to have any manual scrolling, just calls to adjust the axis limits.
This is the baseline code for plotting:
t = 0:1/1000:20;
s = rand(1,length(t)).*sin(0.67*2*pi*t);
ax(1) = subplot(3,1,1);
h1 = plot(t,s);
ax(2) = subplot(3,1,2);
h2 = plot(t,s);
ax(3) = subplot(3,1,3);
h3 = plot(t,s);
Now I'd like to do something like the following:
update_tick = 0;
for t2 = 0:0.01:18
update_tick = update_tick + 1;
if mod(update_tick,5) == 0
xtick = t2:0.1:t2+2;
The code above changes to the x-limits to simulate scrolling/new data and occasionally updates the displayed ticks.
This code however is horribly slow. This takes about 50 seconds to run on my computer. It gets faster if the drawnow is replaced with pause (about 12s) but I have other things to do in the DAQ collection loop and I'd like this number to be closer to 1-2 seconds. For reference, Matlab 2017b documentation states that using the pause function is equivalent to the drawnow command, but I find I like this explanation better (basically a drawnow if possible within allotted time): https://www.mathworks.com/matlabcentral/answers/7309-is-pause-a-superset-of-drawnow#answer_192103
Additionally, as the plotting is occurring the axes are shaking just slightly which is really annoying.
Any suggestions on speeding up the code?