필터 지우기
필터 지우기

filtering problem of dates

조회 수: 2 (최근 30일)
AA
AA 2017년 11월 1일
답변: Cam Salzberger 2017년 11월 1일
circa1 = xlsread(fileToRead);
[numOnly, textOnly, rawDataInCellArray] = xlsread(fileToRead);
Dates=textOnly(~cellfun('isempty',textOnly));
matchresult = regexp(Dates, '(?<day>\d+)/(?<month>\d+)/(?<year>\d+)');
nomatch = cellfun(@isempty, matchresult);
dateless = Dates(nomatch);
datelike = Dates(~nomatch);
dateliketime=datetime(datelike);
liatime=dateliketime.Month == 10;
Warning: Successfully read the date/time strings using the format 'MM/dd/uuuu', but their format is ambiguous and could also be
'dd/MM/uuuu'. Specify a format string to avoid ambiguity.
> In guessFormat (line 59)
In datetime (line 589)
I get the above error. The filtering is wrong because the format string is not properly defined. I want dd/MM/uuuu. I cannot filter out the month October successfully.

채택된 답변

Cam Salzberger
Cam Salzberger 2017년 11월 1일
As the warning suggests, try specifying the correct 'InputFormat' when you call datetime.
datelike = {'01/10/2017' ; '02/10/2017'};
dt = datetime(datelike)
Warning: Successfully read the date/time text using the format 'MM/dd/uuuu', but their
format is ambiguous and could also be 'dd/MM/uuuu'. Specify a format character vector
to avoid ambiguity.
> In guessFormat (line 66)
In datetime (line 612)
dt =
2×1 datetime array
10-Jan-2017
10-Feb-2017
versus:
datelike = {'01/10/2017' ; '02/10/2017'};
dt = datetime(datelike, 'InputFormat', 'dd/MM/uuuu')
dt =
2×1 datetime array
01-Oct-2017
02-Oct-2017
-Cam

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by