MATLAB: Rearrange any matrix Randomly with a specific sequence

rearrange any matrix randomly

Hello,
I have a Matrix A like this
A=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20]'
I want to redistribute the matrix but I want to preserve a specifc sequence which is 5 here.
I mean I need a way to redistribute each five element randomly and assign them to a new matrix
for example:
the matrix B will be like this:
B=[6 7 8 9 10 11 12 13 14 15]'
the matrix C will be like this:
C=[ 1 2 3 4 5 16 17 18 19 20]'
Is that possible in MATLAB ?
Thanks,

Best Answer

Here is an example that you can refer
a = 1:20;
b = randperm(4);
n = length(b);
for i = 1:n
c(5*(i-1)+1:5*i) = a(5*(b(i)-1)+1:5*b(i));
end