Changing a double type cell in "HH:MM:SS" format.
24 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ramo Rafsel
am 6 Okt. 2020
Kommentiert: Ramo Rafsel
am 7 Okt. 2020
I have a time column which has a double type, "4.099215427200000e+09" as an example of one cell of the whole column.
Is there a way how to change the whole column format in a date format " HH:MM:SS"?
8 Kommentare
Bjorn Gustavsson
am 6 Okt. 2020
OK, so now you've explained that the time-unit is ms (perhaps?). That takes us to the result that your first data (4.099215427200000e+09) is 47.445 days from your date-zero. If you can tell datestr what that date-zero is you've solved your problem.
Akzeptierte Antwort
Steven Lord
am 6 Okt. 2020
What duration do you expect 4.099215427200000e+09 to represent? If you give us one piece of a Rosetta stone we may be able to help interpret your data. Based on your equation this might be what you're looking for:
du = seconds(4.099215427200000e+09/1000);
du.Format = 'hh:mm:ss'
How did you obtain the value of about 4.099e9 from your Excel file? How did you read that data into MATLAB?
Looking at your file and manually copying the value from cell A1 into MATLAB, I think this is what you want:
du2 = seconds(47445960)/1000;
du2.Format = 'hh:mm:ss'
3 Kommentare
Stephen23
am 7 Okt. 2020
Bearbeitet: Stephen23
am 7 Okt. 2020
"I obtained the value through the calculation that I was given, which was: the given time values (Column A in picture 1)*1000/24/60/60)"
I very much doubt that, you won't get anything close to 4e9:
>> val = 47444524; % cell A1 of your Excel worksheet.
>> val*1000/24/60/60 % your own calculation.
ans =
5.4913e+05
Whatever you did to get 4e9 is something quite different, which so far you have not shown us or explained. Not that it really matters, because that very strange value does not help us anyway.
Apparently the input value is simply a duration in milliseconds (it would have saved everyone a lot of time if you had just explained that in the beginning), in which case Steven Lord's answer gives what you are looking for:
>> du = seconds(val)/1000;
>> du.Format = 'hh:mm:ss'
du =
13:10:44
>> du.Format = 'hh:mm:ss.SSS'
du =
13:10:44.524
>> round(du) % Excel rounds to the nearest second, which is an abomination.
ans =
13:10:45
Weitere Antworten (1)
Bjorn Gustavsson
am 6 Okt. 2020
Well you get an output from datestr:
datestr(4.099215427200000e+09,'yyyy mm dd HH:MM:SS')
ans =
'3270 08 21 04:47:59'
You will have to give some additional information about the start of your time-scale, see the help and documentation of datestr, datenum ans datevec. Matlab's date-format is in fractional days since 0-0-0 0:0:0, unix-time is in seconds since 1970 01 01 00:00:00 (IIRC?).
HTH
0 Kommentare
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!