## Datetime conversion in numeric form (matrix)

Fe Mav

### Fe Mav (view profile)

さんによって質問されました 2019 年 7 月 7 日

### Star Strider (view profile)

さんによって コメントされました 2019 年 7 月 10 日
Star Strider

### Star Strider (view profile)

さんの 回答が採用されました
So, I have been trying to convert date to a number and add it to the first column of a numeric matrix.
Unfortnatelly, I use the code below to create the matrix for a specific range of dates but the dates were imported as strings not numbers (see picture). i have no dea why this doesn't work. Any idea?
t1=datetime([2001 01 01 00 00 00]);
t2=datetime([2017 12 31 23 00 00]);
t=[t1:1/24:t2];
time = datetime(t); %this is where the conversion should have happened
time=time';
Firstly, I set the starting and finishing point and then, I choose to insert data by the hour.
After that I try but fail to do the numeric conversion.
Any help is appreciated!

#### 0 件のコメント

サインイン to comment.

R2018b

## 2 件の回答

### Star Strider (view profile)

2019 年 7 月 7 日
採用された回答

If you want to convert them into date numbers, use the datenum function:
timeNr = datenum(time);
If you want to convert them into something else numeric, please be specific.

Fe Mav

### Fe Mav (view profile)

2019 年 7 月 10 日
I was told that Matlab "reads" date as a number and I'm new to this so I think that datenum is what I need. Thanks a lot!
Star Strider

### Star Strider (view profile)

2019 年 7 月 10 日
As always, my pleasure!

サインイン to comment.

### Steven Lord (view profile)

2019 年 7 月 7 日

Rather than converting your datetime array into a number to combine it with a numeric array, consider creating a timetable array instead.

Fe Mav

### Fe Mav (view profile)

2019 年 7 月 10 日
What is that?
Stephen Cobeldick

### Stephen Cobeldick (view profile)

2019 年 7 月 10 日

サインイン to comment.

Translated by