You don't have another option than just hardcoding the number of days in a month. You can do this in a fancy way using the date functions in Matlab, or just look at a calender. The fact that you have 365 days means that you are dealing with a non-leap year, so February only has 28 days.
There are probably simpler ways to solve it, but you can easily convert this 3D matrix to a cell array, apply the function you already suggested to each cell and then convert back to a 3D matrix.
A=rand(720,360,365);
month_lengths=[31 28 31 30 31 30 31 31 30 31 30 31];
B=mat2cell(A,size(A,1),size(A,2),month_lengths);
B=cellfun(@(x) mean(x,3),B,'UniformOutput',false);
B=cell2mat(B);
Best Answer