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?
A(i,:,:)
need to be permuted the same way. This is what I mean 'keeping columns intact'.A(i,randperm(size(A,2)),randperm(size(A,3))
does not give me enough permutation. It's basically permutation of page index inside column index. – yukA(i,randperm(size(A,2)),randperm(size(A,3))
. All columns and pages permuted the same way. To better understand my point tryx = reshape(1:24,4,6); x(randperm(4),randperm(6))
– yuk