Prev: Nullpointer exception when calling javabuilder class in Mac os 10.5.8
Next: Apply filter to image
From: Al on 21 Apr 2010 11:49 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 21 Apr 2010 12:15 "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 21 Apr 2010 13:09 % 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 21 Apr 2010 13:39 James, thanks for the link I will take a look over the material. Bruno, thanks for that clever code. Much appreciated!
|
Pages: 1 Prev: Nullpointer exception when calling javabuilder class in Mac os 10.5.8 Next: Apply filter to image |