function B=annsum(A)

% A is a matrix with data at a quarterly frequency. First column are
% matlabdates
%Translate into yearly.
 
rows=size(A,1);
cols=size(A,2);

B=zeros(rows/4+2,cols);
%Dates: compute the annual average
for j=4:4:rows
    B(j/4,1)=(A(j-3,1)+A(j-2,1)+A(j-1,1)+A(j,1))/4;
end

%Data: compute the annual sums
for i=2:cols
    for j=4:4:rows
        B(j/4,i)=A(j-3,i)+A(j-2,i)+A(j-1,i)+A(j,i);
    end
end
