MATLAB: How to average along all permutations of a 4D array

arrayssymmetry

I was looking for an efficient way of averaging along all permutations of a 4D array, in other words enforce super-symmetry. Given a 4D array ?, I want to compute such that:
where p is all the permutations of .
For a 2D array it is easy to enforce symmetry by setting . Is there something similar for a 4D array?

Best Answer

Why not as follows?
assert( all(size(A)==size(A,1) ) & ndims(A)==4 , 'A must be NxNxNxN')
p=perms(1:4);
B=0;
for i=1:24
B=B+permute(A,p(i,:));
end
B=B/24;