フィルターのクリア

convert datetime format to numeric format

2 ビュー (過去 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 Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by