I am trying to create an animated plot. The pause command inside an infinite loop is supposed to created the timing for me:
t = 0:1/16000:1;
y = sin(2*pi*4*t);
h = plot(t,y);
xlim([ 0 t(end)]);
ylim([ -1 1]);
h.XDataSource = 't';
h.YDataSource = 'y';
rate = 10;
y = sin(2*pi*freq*t);
freq = freq + 0.1;
if freq > 40
freq = 4;
When I try this tic toc shows some inconsistent timing:
Elapsed time is 0.100041 seconds.
Elapsed time is 0.599817 seconds.
Elapsed time is 0.100195 seconds.
Elapsed time is 0.100100 seconds.
Elapsed time is 0.499797 seconds.
Elapsed time is 0.100046 seconds.
If I remove everything from the loop and leave just the pause command it behaves the same.
I tried using java's sleep command but that does not allow the plots to be updated until the loop is exited which is useless.
The results shown above happens whn I run this on Linux. I tried running the same code on Windows and it works fine. Not sure what could be the reason.