function p = sym_perm(n, A, B) %A should be a matrix that contains the numbers 1 through n, once each, and %have all other entries zero. B should be the same as A except that the %nonzero entries are permuted. Function returns a 1xn vector representing %the permutation. [l, w] = size(A); for i = 1:l for j = 1:w if A(i, j) p(A(i, j)) = B(i, j); end end end