Pause function in matlab for specified time

4 次查看(过去 30 天)
Hi all,
I am writing a program that creates a plot of a 4-bar mechanism with a driver crank rotating a full 360 degrees. My plot refreshes every 1 degree, showing the positions of all the links for every degree (361 different plots). I want the plotting to last 15 seconds, but I can't seem to determine how to do this. Below is the code I currently use, but it is not accurate enough. It somehow lasts close to 20 seconds.
format longg
total_time = 15; %seconds
nom_wait = total_time / 361; %seconds
start_time = tic;
for m=1:361
time = clock;
plot(x(:,m),y(:,m),'-r')
title('Centerline Plots of Mechanism Links')
axis equal
axis([-100 20 -20 100])
if (361-m)~=0
elapsed_iteration = etime(clock,time)
total_elapsed = toc(start_time);
time_left = total_time - total_elapsed
if (361-m)>0
wait1 = nom_wait - elapsed_iteration
wait2 = time_left / (361-m)
end
end
pause(wait2)
fprintf('Time Elapsed: %.4f \n',total_elapsed)
end
From my understanding, this should calculate the time it needs to pause between each plot iteration, but it doesn't complete after the 15 seconds. Is this a program issue where my calculations are incorrect, or is it too difficult for the computer to pause more precise than 0.01 seconds?
Thank you for the help!

回答(1 个)

per isakson
per isakson 2013-10-6

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by