From: Al on
Hello All
I'd like to randomly reorder an array of arbitrary size m x n but keep the elements that are in row m_i in that same row.
in a for loop it would be something like

for i=1:size(array,1)
holder=array(i,:)
array(i,:)=holder(randperm(size(holder,2)));
next i

is it possible to use randperm to generate m rows of randomised integers 1 to n? Would some other method be more appropriate?
From: James Tursa on
"Al " <alek.maxwell(a)eon.com> wrote in message <hqn6pg$mrh$1(a)fred.mathworks.com>...
> Hello All
> I'd like to randomly reorder an array of arbitrary size m x n but keep the elements that are in row m_i in that same row.
> in a for loop it would be something like
>
> for i=1:size(array,1)
> holder=array(i,:)
> array(i,:)=holder(randperm(size(holder,2)));
> next i
>
> is it possible to use randperm to generate m rows of randomised integers 1 to n? Would some other method be more appropriate?

This FEX submission might help:

http://www.mathworks.com/matlabcentral/fileexchange/27076-shuffle

James Tursa
From: Bruno Luong on
% Data
A=reshape(1:50,5,10)'

% Engine
[m n] = size(A);
[~, col] = sort(rand(m,n),2);
B = A(bsxfun(@plus,(col-1)*m,(1:m).'))

% Bruno
From: Al on
James, thanks for the link I will take a look over the material.
Bruno, thanks for that clever code.
Much appreciated!