function S=time2sec(t) %TIME2SEC Converts the time in seconds. % % S = TIME2SEC(TIME) % % TIME can be a string in the format 'hh:mm:ss' % or a vector of 3 elements [hh mm ss]. % Return the number of seconds. % % See also: SEC2TIME TIME CLOCK TIC TOC ETIME % % Claudio 7 June 1995. % % % % Copyright (c) 1995 by Claudio Rivetti and Mark Young % claudio@alice.uoregon.edu, mark@alice.uoregon.edu % if nargin < 1 error('Not enough input arguments.'); end if nargin > 1 error('Too many input arguments.'); end if isstr(t) if length(t) ~=8 | t(3)~=':' | t(6)~=':' error('Input string must be in the format hh:mm:ss'); end else if length(t) ~= 3 error('Input vector must contein 3 elements [hh, mm, ss]'); end end if isstr(t) h=str2num(t(1:2)); m=str2num(t(4:5)); s=str2num(t(7:8)); else h=t(1); m=t(2); s=t(3); end S = s + m*60 + h*3600; return