convert datetime format to numeric format
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Poulomi Ganguli
le 28 Août 2017
Commenté : Ahmed Darwish
le 23 Juil 2020
Hi,
I have a matrix in datetime format
'01-Jan-1983 00:00:00'
'01-Jan-1983 01:00:00'
'01-Jan-1983 02:00:00'
'01-Jan-1983 03:00:00'
'01-Jan-1983 04:00:00'
'01-Jan-1983 05:00:00'
'01-Jan-1983 06:00:00'
'01-Jan-1983 07:00:00'
'01-Jan-1983 08:00:00'
'01-Jan-1983 09:00:00'
'01-Jan-1983 10:00:00'
'01-Jan-1983 11:00:00'
'01-Jan-1983 12:00:00'
'01-Jan-1983 13:00:00'
'01-Jan-1983 14:00:00'
'01-Jan-1983 15:00:00'
'01-Jan-1983 16:00:00'
'01-Jan-1983 17:00:00'
'01-Jan-1983 18:00:00'
'01-Jan-1983 19:00:00'
'01-Jan-1983 20:00:00'
'01-Jan-1983 21:00:00'
'01-Jan-1983 22:00:00'
'01-Jan-1983 23:00:00'
I want to convert it to numeric format as follows:
1983 1 1 0
1983 1 1 1
1983 1 1 2
1983 1 1 3
1983 1 1 4
1983 1 1 5
1983 1 1 6
1983 1 1 7
1983 1 1 8
1983 1 1 9
1983 1 1 10
1983 1 1 11
1983 1 1 12
1983 1 1 13
1983 1 1 14
1983 1 1 15
1983 1 1 16
1983 1 1 17
1983 1 1 18
1983 1 1 19
1983 1 1 20
1983 1 1 21
1983 1 1 22
1983 1 1 23
What should be the syntax for this?
1 commentaire
Jan
le 28 Août 2017
I would be useful if you post exactly, what your input is. A code to recreate it is better that the text description "I have a matrix in datetime format". You data look like a cell string. Correct?
Réponse acceptée
Jan
le 28 Août 2017
V = datevec(YourMatrix);
V = V(:, 1:4);
Depending on what exactly your input is, this might need some modifications.
2 commentaires
Ahmed Darwish
le 23 Juil 2020
If i want to make the output time only in hours, minutes and second but in only one column, what can I do?
Plus de réponses (1)
Peter Perkins
le 29 Août 2017
While you asked to be able to convert timestamps strings into (partial) date vectors, you may find that if you convert your strings to datetimes, you can just work with those. You don't say what you plan on doing with the datevec, so there's no way of knowing. But one of the main reasons why the datetime data type was introduced was to replace all the conversion back and forth that was part and parcel of the old datenumn/datevec/datestr triad.
0 commentaires
Voir également
Catégories
En savoir plus sur Characters and Strings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!