Reputation: 5559
I have 1 vector representing some of the days of a week
daysweek = [5 6 7 1 2 3]; % (1 = sunday, 2= monday,..., 7 = saturday)
I want to count how many sundays, mondays etc are present in my vector.
What I do is define a vector:
uniquedays = [1 2 3 4 5 6 7];%sorted so I can use hist
count how many instances present in my original vector "daysweek" exists in uniquedays.
countdays = hist(daysweek, uniquedays);
countdays will be then 1 1 1 0 1 1 1.
My problem is that I would like to have countdays with the first element referring to Monday and not to Sunday so it should be 1 1 0 1 1 1 1
(like if uniquedays is 2 3 4 5 6 7 1)
Thanks
Upvotes: 0
Views: 85
Reputation: 30579
Try circshift
:
countdays = hist(daysweek, uniquedays);
countdays = circshift(countdays,[0 -1]);
Upvotes: 2