"Woo Kim" <efreet84@hanmir.com> wrote in message
news:hruf1g$qua$1@fred.mathworks.com...
> Hi all I hope you're having nice days. I've spent way too much time on
> this problem... I need your help :(
>
> I'll try to describe my problem clearly first, and then I'll just tell you
> exactly what I want to do. So I need to randomly subsample from a matrix.
> 'randsample' would be perfect, but I need to sample from a twodimension
> array, and running randsample twice would mix up indices of the pairs. I
> thought about 'randi' to get indices first and then sample with them, but
> I noticed randi can return same value, which I have to avoid.
>
> So flat out, I need to randomly sample 150 pairs of data from 250 pairs.
> (and I need 20 different sample sets) With studying 20 sample sets, I'm
> going to estimate the behavior of the original 250 pairs.
>
> Sounds a lot like a homework right? :) yes, shamelessly I admit, this is a
> homework! But at least I'm doing it very much ahead of time and spent a
> lot of time by myself before asking here, so plz don't hate!
I agree with Sean's suggestion that you should look at RANDPERM.
M = magic(4);
numElements = numel(M);
indicesOfAllPoints = randperm(numElements);
fiveRandomElements = M(indicesOfAllPoints(1:5))
This uses "linear indexing"  you can search the documentation for that
term for more information. Alternately, if you want to randomly select a
subset of rows:
M = magic(10);
numRows = size(M, 1);
shuffledRows = randperm(numRows);
fiveRandomRows = M(shuffledRows(1:5), :)
But the procedure you describe sounds like you might be interested in this
section of the Statistics Toolbox documentation:
http://www.mathworks.com/access/helpdesk/help/toolbox/stats/f7462.html

Steve Lord
slord@mathworks.com
comp.softsys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
