Applying within range function

조회 수: 5 (최근 30일)
Adnan Jayyousi
Adnan Jayyousi 2022년 6월 23일
답변: Steven Lord 2022년 6월 23일
Hello everyone,
I am trying to check if ceratin days are withing a specific range, using the withinrange function.
The code is :
%% Define date&time arrays :
t1 = datetime(2021,1,1,0,0,0);
t2 = datetime(2021,12,31,23,0,0);
DateNtime = (t1:hours(1):t2)'
DateNtime = 8760×1 datetime array
01-Jan-2021 00:00:00 01-Jan-2021 01:00:00 01-Jan-2021 02:00:00 01-Jan-2021 03:00:00 01-Jan-2021 04:00:00 01-Jan-2021 05:00:00 01-Jan-2021 06:00:00 01-Jan-2021 07:00:00 01-Jan-2021 08:00:00 01-Jan-2021 09:00:00 01-Jan-2021 10:00:00 01-Jan-2021 11:00:00 01-Jan-2021 12:00:00 01-Jan-2021 13:00:00 01-Jan-2021 14:00:00 01-Jan-2021 15:00:00 01-Jan-2021 16:00:00 01-Jan-2021 17:00:00 01-Jan-2021 18:00:00 01-Jan-2021 19:00:00 01-Jan-2021 20:00:00 01-Jan-2021 21:00:00 01-Jan-2021 22:00:00 01-Jan-2021 23:00:00 02-Jan-2021 00:00:00 02-Jan-2021 01:00:00 02-Jan-2021 02:00:00 02-Jan-2021 03:00:00 02-Jan-2021 04:00:00 02-Jan-2021 05:00:00
Holidays = datetime({'2021-03-27';'2021-03-28';'2021-04-02';'2021-04-03';
'2021-04-14';'2021-04-15';'2021-5-16';'2021-05-17';'2021-09-06';'2021-09-07';'2021-09-15';'2021-09-16';'2021-09-20';'2021-09-27'});
rangeOfTimes = timerange(t1,t2);
tf = withinrange(Holidays(1,1), rangeOfTimes);
Check for incorrect argument data type or missing argument in call to function 'withinrange'.
-----
In the "tf" array i am getting argument error. What causes the error ?
Thanks

채택된 답변

Steven Lord
Steven Lord 2022년 6월 23일
The withinrange function requires its first input to be a timetable, not a datetime array. You probably want isbetween instead.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calendar에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by