how can I move a Point in a plot (GUI) from one side to the other in a fixed time?
9 views (last 30 days)
I have a point in a plot and I want to move it "smoothly" to the other side of the plot within a fixed amount of time. In the example this time is 3s, and I refresh the plot "every 20ms" (20ms is what I want, but it's always more, between: 30 and 50ms). My code is:
set(pointHandle,'Xdata',point(1).coordinatesNow(1)+(500/150),'Ydata',point(1).coordinatesNow(2)); %Only refresh Xaxis
pause(0.02); %pause of 20ms
a=a+etime(clock,iTime); %total elapsed time
disp(a); %show total time
So I'd like "a" to be 3s, but most of the times is between 7 and 10s, How could I get more accuracy?
Robert Cumming on 19 Oct 2014
Edited: Robert Cumming on 20 Oct 2014
edit: changed timing to an overall target for loop instead of interval time.
See the code below:
ax = axes;
x = [0:100];
h = plot ( ax, x, x*0 );
ax.YLim = [0 100];
targetTime = 3;
nSteps = 100;
intervalTime = targetTime./nSteps;
loop = tic;
h.YData(:) = ii;
timeTaken = toc(loop);
% comment out this line to see the effet of the pause
When I run this in matlab I get the following:
Elapsed time is 1.174296 seconds. (pause commented out)
Elapsed time is 3.006906 seconds.