help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: timer function workaround tia sal22


From: Moo
Subject: Re: timer function workaround tia sal22
Date: Wed, 2 Feb 2011 21:39:17 -0700

On Wed, Feb 2, 2011 at 2:10 PM, ratulloch <address@hidden> wrote:

Example of what I'm trying to do
1) have several objects that go from 0-360 degrees
incrementing by 1
2) the clock example is the best one I can think of
0-360 degrees in 1 second
0-360 degrees in 1 minute
0-360 degrees in 1 hour
Is there a way to do this without user the timer function?
tia sal22

A naive (and not very accurate) way to do it is:

If you have multiple time intervals you want (seconds, minutes, hours), choose the smallest (in your case, a second) and then use a while loop with the sleep() or pause() function.  You can increment the degrees according to basic ratios, for instance, every 60th iteration you can move the minute hand forward 6 degrees.

This isn't going to be a very accurate clock though, as you lose time cycling through the loop; for example:

>while 1
tic; pause(1); toc
end

Elapsed time is 1.013892 seconds.
Elapsed time is 1.013938 seconds.
Elapsed time is 1.013877 seconds.
Elapsed time is 1.013991 seconds.
Elapsed time is 1.013864 seconds.



This also means if you're looking to do something accurate to 3+ digits (or have a clock hands running smoothly) you'll need a different solution.  Or you could play around with compensating for the overhead in the loop.  Anyway.  I'm sure someone will swoop in right after me and have a magic function I couldn't find.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]