MATLAB: How to generate random matrix from another one

19.09.2019

Hi!
I have a 18 x 57×11 matrix .
How can I make a new random matrix (the same size) , which is generated by "shuffling" the values of the original matrix?
A lot thanks in advance!

Best Answer

You can use randperm() to shuffle the values of array 'm'.
% Original array
m =rand(180, 57, 11);
% Random permutation index
randpermIdx = randperm(numel(m));
% m shuffled
mShuffle = reshape(m(randpermIdx), size(m));
To convince yourself that mShuffle is merely a random reorganization of m with no additional or missing values or duplicate samples, use this line below which should return True.
isequaln(sort(m(:)),sort(mShuffle(:)))