フィルターのクリア

assign categorical value for weekday variables

3 ビュー (過去 30 日間)
Sehoon Chang
Sehoon Chang 2020 年 9 月 25 日
コメント済み: Sehoon Chang 2020 年 9 月 25 日
Dear advisors,
how may i assign categorical value for weekday variables?
I have made a variable 'weekday' from the datetime record from a timetable, which gave me
1..sunday 2..monday 3.. tueday ........ 6..friday 7..saturday
weekday = weekday(timetable.Properties.RowTimes)
I wish to create 'workingday' using 'weekday'.
Within the variable 'workingday', the numbers 2,3,4,5,6 of 'weekday' shall be assigned the categorical value 1 (workingday). 1 and 7 shall be assigned the categorial value of 0 (non-working day).
thank you.

採用された回答

Steven Lord
Steven Lord 2020 年 9 月 25 日
Since you have a timetable you can use the isweekend function to get true and false values (which you could convert to categorical or leave as logical) from the RowTimes property.
% Make some sample data
T = datetime('today');
thisWeek = T + days(0:6);
% Process each day
for whichDay = 1:numel(thisWeek)
D = thisWeek(whichDay);
if isweekend(D)
fprintf("%s is not a weekday.\n", D)
else
fprintf("%s is a weekday.\n", D);
end
end
If you wanted to get a categorical array, consider calling categorical on the output of day with the 'dayofweek' input.
  2 件のコメント
Sehoon Chang
Sehoon Chang 2020 年 9 月 25 日
Hi,
thanks for the reply.
weekend = isweekend(timetable.Properties.RowTimes)
As you have suggested, the above stated code would show me the days when the timestamps are weekends by 1, and the weekdays with 0.
How may i reverse the outcome, sothat i get 0 for weekends and 1 work weekdays?
Sehoon Chang
Sehoon Chang 2020 年 9 月 25 日
ah.... solved thank you.
'~isweekend'

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by