convert datetime format to numeric format

3 Ansichten (letzte 30 Tage)
Poulomi Ganguli
Poulomi Ganguli am 28 Aug. 2017
Kommentiert: Ahmed Darwish am 23 Jul. 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 Kommentar
Jan
Jan am 28 Aug. 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?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jan
Jan am 28 Aug. 2017
V = datevec(YourMatrix);
V = V(:, 1:4);
Depending on what exactly your input is, this might need some modifications.
  2 Kommentare
Poulomi Ganguli
Poulomi Ganguli am 28 Aug. 2017
Thanks its working!
Ahmed Darwish
Ahmed Darwish am 23 Jul. 2020
If i want to make the output time only in hours, minutes and second but in only one column, what can I do?

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Peter Perkins
Peter Perkins am 29 Aug. 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.

Kategorien

Mehr zu Dates and Time 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!

Translated by