필터 지우기
필터 지우기

Convert time in decimal days into hh:mm:ss format

조회 수: 35 (최근 30일)
Zach Morag
Zach Morag 2021년 12월 5일
편집: TAMRABET 2023년 1월 27일
Hi all,
Just encounter some issue regarding converting time logs from excel
when I used readtable functrion the time from excel was hh:mm:ss and ocnverted at MATLAB to decimal in days
for example: 12:06:30 in excel was converted to 0.504513888888889 in MATLAB.
so how can I conerted to hh:nn:ss?

답변 (2개)

Stephen23
Stephen23 2021년 12월 5일
편집: Stephen23 2021년 12월 5일
N = 0.504513888888889;
T = days(N);
T.Format = 'hh:mm:ss'
T = duration
12:06:30
or
D = datetime(N,'ConvertFrom','excel');
T = timeofday(D)
T = duration
12:06:30
  댓글 수: 11
Stephen23
Stephen23 2021년 12월 6일
Zach Morag's incorrectly posted "Answer" moved here:
if Im using days, as you wrote, the output is this:
and if Im using datetime:
scaleLog.('Time [hh:mm:ss]') = datetime(scaleLog{:,2},'ConvertFrom','excel');
scaleLog{:,2}.Format = "HH:mm:ss";
the output is that:
How can I remove the date and remain only with the time?
Stephen23
Stephen23 2021년 12월 6일
편집: Stephen23 2021년 12월 6일
@Zach Morag: Yes, can I remember meeting this exact issue a few years ago. Apparently it is not possible to use curly-brace indexing to change the format of an already existing datetime variable in a table:
D = datetime(2021,12,[1;31]);
N = [2;3];
T = table(D,N)
T = 2×2 table
D N ___________ _ 01-Dec-2021 2 31-Dec-2021 3
T{:,1}.Format = 'yyyy-MM-dd' % Using indexing does not work...
T = 2×2 table
D N ___________ _ 01-Dec-2021 2 31-Dec-2021 3
T.D.Format = 'yyyy-MM-dd' % but using variable names works!
T = 2×2 table
D N __________ _ 2021-12-01 2 2021-12-31 3
The same might apply to other object types, e.g. duration.

댓글을 달려면 로그인하십시오.


TAMRABET
TAMRABET 2023년 1월 27일
편집: TAMRABET 2023년 1월 27일
please check my profile I made a script very usefull to solve that problem, click here :

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by