Problem with input for the datetime function

I have a cell array containing strings that describe a date. It looks like this:
datum=
'01.06.2014'
'02.06.2014'
'03.06.2014'
'04.06.2014'
'05.06.2014'
I want to convert them to a Matlab recognised date array, so that I can ultimately determine in which Calender Week they fall in (using the function week)
My code looks like this:
%reading in the data file and isolating the weekday column
dateiname='ABGERUFENE_SRL_BETR_IST-WERTE_20140601_20140630_Netzregelverbund_20150408-225302.CSV';
[num text raw]=xlsread(dateiname);
raw([1 2 3 4 5],:) = [];
datum=raw(:,1)
%conversion into date
datum=datetime(datum, 'InputFormat','dd.mm.yyyy');
However this returns the error message: ??? Undefined function or method 'datetime' for input arguments of type 'cell'. It should be able to handle a string, so I don't understand the problem. I have used the query
iscellstr(datum)
which returns a 1, so I really don't know why the error appears. I have also tried using the "text" data - that doesn't work either.
Any help troubleshooting will be much appreciated!!!!!

댓글 수: 1

Guillaume
Guillaume 2015년 7월 9일
Your datum is not a string, it's a cell array of string. These are two different types. It should not matter however, as datetime can handle both types.
Which version of matlab are you using?
Also note that your input format is wrong, it should be: 'dd.MM.yyyy'. datenum and datetime use different format symbols for minutes and months)

댓글을 달려면 로그인하십시오.

 채택된 답변

Sean de Wolski
Sean de Wolski 2015년 7월 9일

0 개 추천

datetime was released in R2014b so if you're using an earlier release, you'll need to upgrade to use it.
This works fine for me in 15a (though you need to use MM instead of mm months instead of minutes).
datum=datetime({'08.07.2015'}, 'InputFormat','dd.MM.yyyy');

댓글 수: 1

Ahhh... that solves it... I've been working with a older version...
Thanks a lot for the quick response!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

질문:

2015년 7월 9일

댓글:

2015년 7월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by