This one is cute... :) Unfortunately, timetable won't accept a 2D array by row so have to do things directly...
t=linspace(datetime(1995,1,1),datetime(1995,12,31),300).'; % 300 elements between above start, stop
[r,c,p]=size(A); % sizes of data, A
M=(splitapply(@mean,reshape(A,r*c,[]).',findgroups(quarter(t)))); % compute means by quarter by columns
M=reshape(M.',r,c,[]); % reshape back to rxcx4
Substitute your real time vector for t, of course.
I did a trial here to check ordering...
t=linspace(datetime(1995,1,1),datetime(1995,12,31)).'; % only 100 instead of 300
A=randi([50 100],5,5,100); % dummy 5x5 data
M=(splitapply(@mean,reshape(A,25,100).',findgroups(quarter(t)))); % compute means 2D
>> M(:,1:3) % small piece to look at to check
ans =
78.4400 76.6000 75.3200
76.3200 73.2400 74.7200
71.6800 76.7200 83.7200
80.6000 74.3600 74.8000
>>
>> MM=reshape(M.',5,5,4);
>> whos MM
Name Size Bytes Class Attributes
MM 5x5x4 800 double
>> squeeze(MM(1,1,:))
ans =
78.44
76.32
71.68
80.60
>> squeeze(MM(2,1,:))
ans =
76.60
73.24
76.72
74.36
>>
