MATLAB: Separating Matrix by Column By Pattern

allocationcolumnsmatrix manipulationpatterpatternslicing

Hi all,
I have count data based in time. I have a matrix that is essentially counts of an event occurring within 96 15 minute intervals per day over some 300 days. It's shaped like this:
sample = [0, 0 , 1, 5, 0, 0, 2, 3, 2, 0, 1, 4, 0, 0, 1, 2, 5, 0, 0, 0, 1, 1, 0, 1;
1, 0 , 2, 1, 2, 0, 4, 1, 2, 0, 1, 2, 0, 0, 1, 2, 5, 0, 0, 0, 2, 3, 0, 1;
0, 0 , 4, 4, 1, 0, 3, 3, 1, 1, 2, 1, 0, 0, 1, 2, 1, 0, 1, 2, 3, 4, 1, 3;
2, 0 , 1, 5, 0, 0, 2, 1, 2, 0, 1, 4, 0, 0, 1, 2, 5, 0, 0, 0, 1, 1, 0, 2];
% the columns refer to the hour, here 24 hours (so one day)
% the rows refer to the counts of events per 15 minute interval (4 per hour)
My problem is that I need to separate this matrix out into weekdays and weekends. So, I know that I start on a Sunday in my data (but I'd like some kind of if-else statement to check that condition, I do have the day-of-week data stored). Basically, I need to find a way to write a loop to allocate specific columns into a matrix Weekday or Weekend based on if the day the column represents is a weekday or weekend.
So I was thinking of something where, for the case where the data begins on a Sunday, I separate the matrix by taking the first 24 columns and putting them in Weekend, taking the next 120 columns and putting them in Weekday, the next 48 columns to Weekend, and so on. But I'm having an issue writing the code to do this in a nice and fast way. I also want to handle cases when the data doesn't start on Sunday (like, if it was a Monday first, then the pattern would be 120 columns to Weekday, 48 to Weekend, and so on).
% So I want something like this: Assuming the first 24 columns were Sunday:
sample = [0, 0 , 1, 5, 0, 0, 2, 3, 2, 0, 1, 4, 0, 0, 1, 2, 5, 0, 0, 0, 1, 1, 0, 1, 0, 2, 3, 2, 0, 1, 4, 0, 0, 1, 2, 5, 0, 0, 0 , 1, 5, 0, 0, 2, 3, 2, 0, 1;
1, 0 , 2, 1, 2, 0, 4, 1, 2, 0, 1, 2, 0, 0, 1, 2, 5, 0, 0, 0, 2, 3, 0, 1, 5, 0, 0, 2, 3, 2, 0, 1, 4, 0, 0, 1, 2, 5, 0, 0, 0, 1, 1, 0, 1, 0, 2, 3;
0, 0 , 4, 4, 1, 0, 3, 3, 1, 1, 2, 1, 0, 0, 1, 2, 1, 0, 1, 2, 3, 4, 1, 3, 1, 2, 0, 4, 1, 2, 0, 1, 2, 0, 0, 1, 2, 5, 0, 0, 0, 2, 3, 0, 1, 5, 0, 0;
2, 0 , 1, 5, 0, 0, 2, 1, 2, 0, 1, 4, 0, 0, 1, 2, 5, 0, 0, 0, 1, 1, 0, 2, 0, 2, 3, 0, 1, 5, 0, 0, 2, 3, 2, 0, 0, 2, 3, 0, 1, 5, 0, 0, 2, 3, 2, 0];
Weekend = [0, 0 , 1, 5, 0, 0, 2, 3, 2, 0, 1, 4, 0, 0, 1, 2, 5, 0, 0, 0, 1, 1, 0, 1; 1, 0 , 2, 1, 2, 0, 4, 1, 2, 0, 1, 2, 0, 0, 1, 2, 5, 0, 0, 0, 2, 3, 0, 1; 0, 0 , 4, 4, 1, 0, 3, 3, 1, 1, 2, 1, 0, 0, 1, 2, 1, 0, 1, 2, 3, 4, 1, 3; 2, 0 , 1, 5, 0, 0, 2, 1, 2, 0, 1, 4, 0, 0, 1, 2, 5, 0, 0, 0, 1, 1, 0, 2];
Weekday = [0, 2, 3, 2, 0, 1, 4, 0, 0, 1, 2, 5, 0, 0, 0, 1, 5, 0, 0, 2, 3, 2, 0, 1; 5, 0, 0, 2, 3, 2, 0, 1, 4, 0, 0, 1, 2, 5, 0, 0, 0, 1, 1, 0, 1, 0, 2, 3; 1, 2, 0, 4, 1, 2, 0, 1, 2, 0, 0, 1, 2, 5, 0, 0, 0, 2, 3, 0, 1, 5, 0, 0; 0, 2, 3, 0, 1, 5, 0, 0, 2, 3, 2, 0, 0, 2, 3, 0, 1, 5, 0, 0, 2, 3, 2, 0];
And so on. Any ideas? Hope I made sense.

Best Answer

Sounds very easy:
starttime = datetime(2018, 9, 10); %whatever your start is
sampletime = starttime + hours(0:size(sample, 2)-1);
issampleweekend = isweekend(sampletime);
sampleweekday = sample(:, ~issampleweekend);
sampleweekend = sample(:, issampleweekend);
A loop is certainly not needed.