How can I add 5 seconds to the output of the CLOCK function in MATLAB 7.9 (R2009b)?

6 views (last 30 days)
The CLOCK function returns a 1x6 vector. I want to compute "clock + 5 seconds".
For example:
>> clock
ans =
2009 10 6 14 18 9.125
I want to compute clock + 5 seconds, and get a vector [2009 10 5
12 40 01].

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 14 Oct 2009
To do this, you can use the DATENUM and DATEVEC function as an intermediaries:
second = [0 0 0 0 0 1];
datevec(datenum(clock + 5* second))
You can extend this idea to perform any arbitrary day arithmetic:
year = [1 0 0 0 0 0];
month = [0 1 0 0 0 0];
day = [0 0 1 0 0 0];
hour = [0 0 0 1 0 0];
minute = [0 0 0 0 1 0];
second = [0 0 0 0 0 1];
datevec(datenum(clock + 5*second + 4*month + 3*hour + 13*year));

More Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Tags

No tags entered yet.

Products


Release

R2009b

Community Treasure Hunt

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

Start Hunting!