Time conversion question
조회 수: 1 (최근 30일)
이전 댓글 표시
I have several days of data that I am analyzing. There is a time stamp of the form '(DDD)HH:MM:SS.SSSSSS' day, hours, min, sec. Is there an easy of converting this vector to just hours? The date is from the system time of the PC, I just want to plot keep track of a total delta time from the beginning of the data collection to the end. help.
댓글 수: 0
답변 (2개)
Andreas Goser
2011년 1월 28일
Usually, I would prefer the DATEVEC function, but as far as I see, this is not working here, as no month information is given. A very powerful approach is then REGEXP (or FINDSTR, etc.). All in all, with this easy format, the easiest approach is:
dt = datestr(now, '(DDD)HH:MM:SS.FFF')
str2num(dt(6:7))
댓글 수: 0
Sebastian
2011년 1월 28일
I would use the datenum() function to convert your time stamps to a serial date (see "doc datenum" for details). Then I would subtract the minimun of that vector and finally multiply by 24. This would give you the time in hours since the measurement start.
% generate some test data, in your case d would
% be created using the datenum function
d = sort(now+rand(10,1)*2);
d_hours = (d-min(d))*24;
% display for verification
disp([datestr(d) repmat(' -> ',10,1) num2str(d_hours)])
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!