convert datetime format to numeric format

조회 수: 4 (최근 30일)
Poulomi Ganguli
Poulomi Ganguli 2017년 8월 28일
댓글: Ahmed Darwish 2020년 7월 23일
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
Jan
Jan 2017년 8월 28일
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?

댓글을 달려면 로그인하십시오.

채택된 답변

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

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Peter Perkins
Peter Perkins 2017년 8월 29일
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.

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by