In a Serial data receiving process, I have a incoming data
press = {'2016-04-14' '14:18:48' '321'};
datenum(datestr(cellfun(@(x,y) [x y],press(1),press(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 is working wrong?

 채택된 답변

Steven Lord
Steven Lord 2016년 4월 14일

0 개 추천

Look at the char array you're creating with your cellfun call.
>> q = cellfun(@(x,y) [x y],press(1),press(2),'un',0)
q =
'2016-04-1414:18:48'
It looks like somehow datestr is interpreting your string with format 0 (as described in the help text) and treating the 1414 part as a number of days somehow. You can correct this by adding in the missing space:
>> q2 = sprintf('%s ', press{1:2})
I would also recommend that if you're using a release that contains the datetime function that you avoid using serial date numbers and create a datetime instead.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Time Series Objects에 대해 자세히 알아보기

질문:

2016년 4월 14일

댓글:

2016년 4월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by