필터 지우기
필터 지우기

Simple datenum question....I think? I just can't get it to work!

조회 수: 1 (최근 30일)
Red Beard
Red Beard 2012년 11월 7일
Hi all, I'm a bit of a newbie with Matlab so please forgive if this seems a bit basic.
My problem is as follows. I have a string called timestamp which contains a date and a time, e.g. 2009.01.01 00:30. I need to remove the time reading (00:30) and convert the date into a number using the datenum function. I have tried to do this using the following code:
datestamp = identifier.timestamp(1:10) % Removes the time to give only the date
datestamp2 = strrep(datestamp,'.', ',') % Replaces . with , to allow parsing
datestamp3 = datenum(datestamp2) % Should give a number for the date
For some reason this code returns the error,"Error using ==> datevec. 2009 is too large to be a month".
I am obviously doing this the wrong way, but how can I get this to work?
All help is massively appreciated. Thanks.
Red Beard

채택된 답변

Red Beard
Red Beard 2012년 11월 7일
Ok, managed to solve my own problem by reordering the datestamp string using the following code:
yyyy = identifier.timestamp(1:4) % Sets yyyy as the year
mmdd = identified.timestamp(6:10) % Sets mmdd as the month and day
mmddyyyy = strcat(mmdd, '.', year) % Concatenates strings 'mmdd' '.' 'year'
mmddyyyy = strrep(mmddyyyy, '.', ',') % Replaces all '.' with ','
datenum(mmddyyyy)
This now gives me a correct number for the date provided in the timestamp. So for 01,01,2009 I get 733774.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Time Series Objects에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by