%diagonal tensor from m-th order, n-dimensional tensor A
function C=diagt(A)
s=size(A);
C=zeros(s);
n=s(1);
m=length(s);
N=n^m;
ind=cell(1,m);
for i=1:N
    [ind{:}]=ind2sub(s,i);
    indi=[ind{:}];
    if indi(1)==indi(2)
        indC=num2cell(indi);
        C(indC{:})=A(indC{:});
    end
end
