From help-octave-request at bevo dot che dot wisc dot edu Tue Dec 2 22:49:43 2003 Subject: Re: random sort From: Heber Farnsworth To: Mike Miller Cc: Help-Octave List Date: Tue, 2 Dec 2003 22:49:20 -0600 I think your problem is that you are trying to sort something the same size as X when you really only want to sort a vector with as many elements as X has columns. If X is NxM then do [S I] = sort(rand(N,1)); Y = X(:,I); and Y has the same columns as X but in shuffled order. You didn't mention whether you wanted to sample with replacement or not. This just re-orders the columns. It's a different trick if you want to admit the possibility that some columns of X may not show up in Y while others are repeated. That's what you would do if you were boostrapping data for instance. Heber On Tuesday, December 2, 2003, at 09:02 PM, Mike Miller wrote: > I don't know why I can't figure this out! I'd swear I've done it > before. > What's the trick to sorting columns in random order? I have a matrix > with > many columns. Suppose the matrix is called 'X'. It seems like I > should > be able to use something like this: > > [S, I] = sort(rand(size(X))); > > Then I can use 'I' to sort the columns of X, right? But how? I just > know > there's an easy trick. > > Thanks in advance for breaking my mental block. > > Mike > > > > ------------------------------------------------------------- > Octave is freely available under the terms of the GNU GPL. > > Octave's home on the web: http://www.octave.org > How to fund new projects: http://www.octave.org/funding.html > Subscription information: http://www.octave.org/archive.html > ------------------------------------------------------------- > ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------