Maybe this might help (I use the current date and time as an example):
c = datevec(datestr(now)); week_num = ceil(diff(datenum([c(1), 1, 1, 0, 0, 0; c])) / 7)
I'm not sure how this solution handles edges correctly, but I think this is a good place to start.
You can also check it using this website , which reports the current week number.
Applying this to your example can be done, for example, like this:
weeknum = @(v)ceil(diff(datenum([v(1), 1, 1, 0, 0, 0; v(:)'])) / 7); arrayfun(@(n)weeknum(DateTime(n, :)), 1:size(DateTime, 1))'
source share