MaK
MaK

Reputation: 51

Wrong Conversion from datenum

In a Serial receiving process, I have a incoming data

pressure ={'2016-04-14'    '14:18:48'    '321'}
datenum(datestr(cellfun(@(x,y) [x y],pressure(1),pressure(2),'un',0)));

Here, the result of date time serial from above step,

ans = 7.3648e+05`

When I convert back, the result is giving a different time into the future:

datestr(ans)
ans = 29-May-2016 22:18:48

where this working wrong?

Upvotes: 1

Views: 176

Answers (1)

Jonas
Jonas

Reputation: 74940

When you combine date and hour, you need to make sure that there is a space between the date and the hour. Your cellfun call creates the string '2016-04-1414:18:48', which then gets mis-interpreted.

cellfun(@(x,y) [x ' ' y],pressure(1),pressure(2),'un',0)) fixes the problem. Note that you can drop the first call to datestr, and write

numericDate = datenum(cellfun(@(x,y) [x ' ' y],pressure(1),pressure(2),'un',0)))

Upvotes: 2

Related Questions