I have 3D matrix (10000 x 60 x 20) and I need to permute 2nd and 3rd dimensions keeping the columns intact.
For 2D matrix I use RANDPERM:
pidx = randperm(size(A,2));
Aperm = A(:,pidx);
I cannot just apply RANDPERM twice - column index first, then page index. Not enough randomization.
One solution is to reshape the matrix from 3D to 2D squeezing columns and pages to columns, permute them and then reshape back. But I'd also like to do permutation in such a way that columns permuted independently for each page. Something like:
Aperm = zeros(size(A));
for p=1:size(A,3)
pidx = randperm(size(A,2));
Aperm(:,:,p) = A(:,pidx,p);
end
Can I do it more efficiently? Any better ways?