MATLAB: Building an array of the month number for every day of the year

datestr array

I want to build an array of the month of every day of a common year, in numerical format :
for i=1:31
m(i) = 1;
end
for i=32:59
m(i) = 2;
end
...
For the moment, I do it like this :
m = str2double(cellstr(datestr(367:731,'mm')));
% 367:731 instead of 1:365 because 2000 is a leap year
But I'm wondering if there is a better way to do it. Is there ?

Best Answer

Actually, I found the fastest way to do this :
[~,m] = datevec(367:731);
Simple as that...