2.66667

2.7 | 3 ratings Rate this file 38 downloads (last 30 days) File Size: 1.48 KB File ID: #22817

Seconds to hours, minutes, seconds

by Simon Robinson

 

29 Jan 2009 (Updated 02 Feb 2009)

Code covered by the BSD License  

Converts a time in seconds to a time in hours, minutes and seconds.

Download Now | Watch this File

File Information
Description

A very simple program to convert a time in seconds to a string giving the time in hours, minutes and seconds. Useful for producing readable toc output from programs which run for ages.

e.g.

help secs2hms
 SECS2HMS - converts a time in seconds to a string giving the time in hours, minutes and second
 Usage TIMESTRING = SECS2HMS(TIME)]);
 Example 1: >> secs2hms(7261)
 >> ans = 2 hours, 1 min, 1.0 sec
 Example 2: >> tic; pause(61); disp(['program took ' secs2hms(toc)]);
 >> program took 1 min, 1.0 secs

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
29 Jan 2009 Husam Aldahiyat

Name is too long; have to manually change it to s2hms.
Other than that, pretty cool code.

30 Jan 2009 Jos (10584)

This file contains H1 line , no help section and no comments, which makes it rather useless. First, how will you find the name of this file in the future if you cannot use LOOKFOR. Secondly, even if you find it, how will you know how to use it, if you cannot use HELP. Third, the total lack of comments makes it difficult to decipher what an end-user should do. In other words, it is only useful to someone with some matlab skills already. On the other hand, she or he will probably stick to something more matlab-ish like:

TimeInSecs = 7261 ;
disp(datestr(datenum(0,0,0,0,0,TimeInSecs),'HH:MM:SS'))

30 Jan 2009 Jos (10584)

should read: _NO_ H1 line ...

04 Feb 2009 Thorbjorn

Nice! This is useful for extended numerical calculations/ simulaitons. I have developed a similar function a while ago that I find useful (even simpler, but also faster than yours) -- will post it on the web.

Please login to add a comment or rating.
Updates
02 Feb 2009

Function name shortened. H1 line and help added.

Tag Activity for this File
Tag Applied By Date/Time
optimization Cristina McIntire 29 Jan 2009 16:57:16
general Simon Robinson 29 Jan 2009 16:57:22
optimisation Simon Robinson 29 Jan 2009 16:57:22
timing Simon Robinson 29 Jan 2009 16:57:22
strings Simon Robinson 02 Feb 2009 11:48:36
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com