fork download
qtest = ...
@(A)all(sum([A A' (d=@spdiags)(A) d(flip(A))],1)==1)

S = [0 0 0 1 0 0 0 0;
     0 0 0 0 0 0 1 0;
     0 0 1 0 0 0 0 0;
     0 0 0 0 0 0 0 1;
     0 1 0 0 0 0 0 0;
     0 0 0 0 1 0 0 0;
     1 0 0 0 0 0 0 0;
     0 0 0 0 0 1 0 0]
qtest(S)

S = [0 0 0 1 0;
     1 0 0 0 0;
     0 1 0 0 0;
     0 0 0 0 1;
     0 0 1 0 0]
qtest(S)

S = [1 0;
     1 0]
qtest(S)

S = [0 0 1;
     0 0 0;
     0 1 0]
qtest(S)

S = [0 0 1 0;
     1 0 0 0;
     0 0 0 1;
     0 1 0 0]
qtest(S)

S = [1]
qtest(S)

Success #stdin #stdout 0.22s 404544KB
stdin
Standard input is empty
stdout
qtest =

@(A) all (sum ([A, A', (d = @spdiags)(A), d(flip (A))], 1) == 1)

S =

   0   0   0   1   0   0   0   0
   0   0   0   0   0   0   1   0
   0   0   1   0   0   0   0   0
   0   0   0   0   0   0   0   1
   0   1   0   0   0   0   0   0
   0   0   0   0   1   0   0   0
   1   0   0   0   0   0   0   0
   0   0   0   0   0   1   0   0

ans =  1
S =

   0   0   0   1   0
   1   0   0   0   0
   0   1   0   0   0
   0   0   0   0   1
   0   0   1   0   0

ans = 0
S =

   1   0
   1   0

ans = 0
S =

   0   0   1
   0   0   0
   0   1   0

ans = 0
S =

   0   0   1   0
   1   0   0   0
   0   0   0   1
   0   1   0   0

ans =  1
S =  1
ans =  1