How can I easily get for each day in 2013 the type of day? ( Weekday, Saturday, Sunday)

1 次查看(过去 30 天)
Hello, I want to know if there's an easy way to get to know for each day in 2013 if it was a weekday or a Saturday or Sunday. Since the first day is in 2013 was a Tuesday, the result could be something like:
Year2013=[2 3 4 5 6 7 1 2 3 4...] or [1 1 1 1 2 3 1 1 1 1 1 2 3]...
The result can of course look different, I just want to be able to get a "number" for each day, so that I can go through the year with a loop (1:1:365) and get a number each time. Thanks a lot!

采纳的回答

per isakson
per isakson 2014-3-10
编辑:per isakson 2014-3-10
Hint:
>> day_of_year = 1;
>> [ num, str ]= weekday( datenum( 2013, 1, 1 ) + day_of_year - 1 )
num =
3
str =
Tue
and vectorized
>> [ num, str ] = weekday( datenum( 2013, 1, 1 ) + [1:365] - 1 );
>> num(1:7)
ans =
3 4 5 6 7 1 2
With Matlab Sun is weekday 1.
>> str(1:3,:)
ans =
Tue
Wed
Thu
>>
And finally inspired by Sean
[ num, str ]= weekday( datenum( 2013, 1, 1 ) : datenum( 2013, 12, 31 ) );

更多回答(1 个)

Sean de Wolski
Sean de Wolski 2014-3-10
day = weekday(datenum('01/01/2013'):datenum('12/31/2013'))

类别

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