[n,t] = xlsread('data2.xlsx');
tt = {t(:,1),t(1,:)'};
v = cell(2);
for jj = 1:2
t1 = tt{jj}(~cellfun(@isempty,tt{jj}));
[a,b,c] = unique(t1,'first');
[~,ii]=sort(b);
a=a(ii);
[~,iii]=sort(ii);
c=iii(c);
v(:,jj) = {a;c};
end
[x,y] = ndgrid(v{2,:});
d = accumarray([x(:),y(:)],reshape(n(4:end,4:end),[],1));
out = cell(size(d)+2);
out(3:end,1) = v{1,1};
out(1,3:end) = v{1,2}';
out(2:end,2:end) = num2cell([nan,sum(d);sum(d,2),d]);