transforming minutes into time
조회 수: 2 (최근 30일)
이전 댓글 표시
let col1 contain the following values
905
990
1117
1228
1306
16
149
211
276
347
418
478
533
581
631
679
730
795
How can I transform the above values into time HH:MM. 905/60=15,08. or 15:05 o'clock and so on
댓글 수: 0
채택된 답변
Star Strider
2016년 5월 6일
편집: Star Strider
2016년 5월 6일
Your minutes array is rolling over to a new day at index = 5, so this adds days whenever the day ‘resets’.
Version #1 — if you have repelem (new in R2015a):
T2400 = [1; find(diff(Tv) < 0); size(Tv,1)+1];
Tv = Tv + repelem([0:length(diff(T2400))-1], diff(T2400))' * 1440;
Result = datestr(datenum([01 01 01]) + Tv/1440, 'HH:MM')
Version #2 (without repelem):
T2400 = [1; find(diff(Tv) < 0); size(Tv,1)];
days = 0;
for k1 = 1:length(T2400)-1
Tv(T2400(k1):T2400(k1+1)) = Tv(T2400(k1):T2400(k1+1)) + days*1440;
days = days + 1;
end
Result = datestr(datenum([01 01 01]) + Tv/1440, 'HH:MM')
Result =
15:05
16:30
18:37
20:28
21:46
00:16
02:29
03:31
04:36
05:47
06:58
07:58
08:53
09:41
10:31
11:19
12:10
13:15
EDIT — Added ‘Version #1’.
댓글 수: 1
Star Strider
2016년 5월 6일
‘thanks but I need it as cell array with 05:10 not 5:10.’
My code give the leading zeros, as my previous post demonstrates.
What do you want?
‘I have to transform the charr to cell array. how do i do that’
One easy way is to put curly braces ‘{}’ around the right-hand side:
Result = {datestr(datenum([01 01 01]) + Tv/1440, 'HH:MM')}
추가 답변 (2개)
Azzi Abdelmalek
2016년 5월 6일
편집: Azzi Abdelmalek
2016년 5월 6일
a=[90;990;;1117;54;60]
h=fix(a/60)
m=mod(a,60)
out=arrayfun(@(x,y) [sprintf('%d',x) ':' sprintf('%d',y)],h,m,'un',0)
k=datenum(out,'HH:MM')
out=datestr(k,'HH:MM')
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Time Series에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!