time format as hr:min:sec
2 次查看(过去 30 天)
显示 更早的评论
sir, i have three columns- one containing hour, next minute , third on sec.
hr=[10,10,10,10];
min=[00,00,01,01];
sec=[00,30,00,30];
i need a single column of time as
[10:00:00,10:00:30,10:01:00,10:01:30]
what is the method?
0 个评论
采纳的回答
KSSV
2017-1-23
hr=[10,10,10,10];
min=[00,00,01,01];
sec=[00,30,00,30] ;
iwant = [] ;
for i = 1:length(hr)
str = sprintf('%02d:%02d:%02d\n',hr(i),min(i),sec(i)) ;
iwant = [iwant ; str] ;
end
iwant
8 个评论
Stephen23
2017-2-6
@seema niran: note that my Answer works with negative values as well, without error, as well as being simpler and much more efficient that the answer you accepted.
更多回答(2 个)
Stephen23
2017-1-23
编辑:Stephen23
2017-1-23
>> hr=[10,10,10,10];
>> min=[00,00,01,01];
>> sec=[00,30,00,30];
>> fprintf('%02d:%02d:%02d\n',[hr;min;sec])
10:00:00
10:00:30
10:01:00
Or to put it into a string or cell array:
>> S = sprintf('%02d:%02d:%02d\n',[hr;min;sec])
S =
10:00:00
10:00:30
10:01:00
>> C = strsplit(strtrim(S),'\n')'
C =
'10:00:00'
'10:00:30'
'10:01:00'
'10:01:30'
0 个评论
Peter Perkins
2017-2-6
All the previous answers assume you want text, and that may be what you want. But if you're using R2014b or later, you can use durations:
>> hr=[10,10,10,10];
>> min=[00,00,01,01];
>> sec=[00,30,00,30];
>> d = duration(hr,min,sec)
d =
10:00:00 10:00:30 10:01:00 10:01:30
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!