Changing a double type cell in "HH:MM:SS" format.

7 visualizaciones (últimos 30 días)
Ramo Rafsel
Ramo Rafsel el 6 de Oct. de 2020
Comentada: Ramo Rafsel el 7 de Oct. de 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 comentarios
Ramo Rafsel
Ramo Rafsel el 6 de Oct. de 2020
The only thing that I meant by "procedure", is by calculating the time using the equation "Time cell/1000*(1/24/60/60)", to get time values and convert the format in excel manually, you ll see the used equation if you click on the first cell in the column F in the excel file. So there is no "mystery" procedure. I just used what I was given before. And pardon me I am still new to the matlab world, so I am still learning from such problems and from my mistakes also :)
See the attached excel file, and thanks a lot for the help.
Bjorn Gustavsson
Bjorn Gustavsson el 6 de Oct. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Steven Lord
Steven Lord el 6 de Oct. de 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 comentarios
Stephen23
Stephen23 el 7 de Oct. de 2020
Editada: Stephen23 el 7 de Oct. de 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
Ramo Rafsel
Ramo Rafsel el 7 de Oct. de 2020
Thank you @Stephen Cobeldick and @Steven Lord. You solved the problem. I am sorry I could't explain it the best or the easiest way. I guess I have to learn how to better articulate myself.
I made a mistake in my previous comment, it should be "(Column A in picture 1)/1000/24/60/60)" instead of "Column A*1000/24/60/60". So I got the wrong value. Thanks for pointing it out.
And yes the input value is the duration in milliseconds. So it is all clear now.
Thanks a lot again :)

Iniciar sesión para comentar.

Más respuestas (1)

Bjorn Gustavsson
Bjorn Gustavsson el 6 de Oct. de 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

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by