MATLAB: How to create a vector with several repetitions of a random permutation

random permutationrandperm

Hi,
I would like to create a vector y with several repetions i of another randomly sorted vector x, i.e. y = [randperm(x), randperm(x), randperm(x), …], but without repeatedly using randperm().
For example: Given x = [1, 2, 3, 4] I would like to create a vector y = [2, 4, 1, 3, 1, 4, 3, 2] (which contains i = 2 two several random permutations of x).
Is there any function that I can use for this purpose?
Thanks in advance, Alex

Best Answer

x = 1:4;
ii = 2;
x1 = repmat(x(:)',1,ii);
out = x1(randperm(numel(x1)))