How to convert time in milliseconds to hour, minutes format?

3 views (last 30 days)
abdur rauf
abdur rauf on 4 Nov 2021
Edited: abdur rauf on 5 Nov 2021
I want to convert time in millisecons format to hour, minutes format using matlab 2013b. I used the following code to convert milliseconds to seconds;
time_seconds=time/1000;
% Here 'time' is a matrix in milliseconds format. It can be found in the
% attacement. The output matrix 'time_seconds' contains time in seconds.
To convert the time in seconds to hour, minute format, I tried the following code from
s = seconds(time_seconds);
s.Format = 'hh:mm';
from
https://www.mathworks.com/matlabcentral/answers/519116-convert-seconds-to-hours-minutes
After execution of the first line in the above two lines code, I got an error message;
Error using datevecmx
The datevecmx function only accepts double arrays.
Error in datevec (line 301)
y = datevecmx(t);
Error in second (line 46)
c = datevec(d(:));
Any help in solving this problem will be appreciated.
Thanks
  1 Comment
Stephen
Stephen on 4 Nov 2021
"I want to convert time in millisecons format to hour, minutes format using matlab 2013b."
Please explain what output you expect to get: a duration array (not supported on your MATLAB version), numeric array/s (what size/s?), or character array/s (what size/s?) or a cell array (what size?) of character row vectors, or something else?
Given that your data has values on the order of
>> time(1:9,1:9)
ans =
86556152 86610975 86668816 86723356 86784534 86838907 86897188 86951302 87027564
86556108 86611020 86668772 86723402 86784488 86838952 86897142 86951346 87027516
86556062 86611064 86668730 86723446 86784442 86838997 86897097 86951391 87027470
86556014 86611108 86668688 86723490 86784398 86839041 86897054 86951436 87027425
86555966 86611152 86668645 86723536 86784353 86839085 86897008 86951480 87027378
86555920 86611195 86668602 86723581 86784309 86839130 86896963 86951523 87027330
86555875 86611238 86668557 86723626 86784263 86839175 86896920 86951567 87027283
86555831 86611281 86668510 86723669 86784215 86839218 86896875 86951612 87027239
86555789 86611325 86668465 86723713 86784170 86839261 86896829 86951656 87027196
which are larger than 24 hours, do you want to continue counting up the hours to give values >24 hours, to add a days unit, or to take the modulo of every 24 hour, or something else? For example, the first element's value is:
>> double(time(1))/1000/60/60 % hours
ans =
24.0433755555556
what output do you expect for this many hours?
What output do you want for the -999 values the bottom of the columns?

Sign in to comment.

Answers (1)

Yongjian Feng
Yongjian Feng on 4 Nov 2021
What is time_seconds you passed to seconds? It needs to be a double.
s = seconds(1000);
s.Format = 'hh:mm'
  1 Comment
Rik
Rik on 4 Nov 2021
fn=websave('data.mat','https://www.mathworks.com/matlabcentral/answers/uploaded_files/789570/time.mat');
S=load(fn);
class(S.time)
ans = 'int32'
This is supported on R2021b, but not on R2013b.
time=int32(1000);
s = seconds(time);
s.Format = 'hh:mm'
s = duration
00:16

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!