How to a partition a data set of days into weekdays and weekends

1 次查看(过去 30 天)
Hi,
I'm excited to use this site; the previous posts have been immeasurably helpful for me in understanding how to use MATLAB.
I have a data set consisting of active and reactive power measurements for 365 days (1 April 2009 to 30 March 2010), beginning on a Wednesday. The exact dimension of the array is 365x48 (365 days of the year, 48 half-hours). I need to partition the data set into weekdays and weekends, and was wondering if someone could help me understand how this can be done using a MATLAB script?
Ideally I would like to sort the data set into a collection of weekdays in one array, and weekends in a separate array. Any ideas?
Thanks in advance, Torrey

回答(2 个)

Matt Kindig
Matt Kindig 2013-5-13
编辑:Matt Kindig 2013-5-13
Hi Torrey,
I think this should do it:
%Matrix is your 365x48 matrix
%Every 4th and 5th rows are Saturday and Sunday
weekend_indices = sort([4:7:365, 5:7:365]);
weekday_indices = setdiff(1:365, weekend_indices);
Weekdays = Matrix(weekday_indices,:);
Weekends = Matrix(weekend_indices,:);

Sean de Wolski
Sean de Wolski 2013-5-13

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by