From: Ulrik Nash on 8 Jul 2010 04:05 Hi Everyone, Suppose I wish to draw 2 numbers at random without replacement from vector A A = [1 2 3 4 5 6 7 8 9 10] Which command will let me do this in Matlab? Best, Ulrik.
From: Jan Simon on 8 Jul 2010 04:29 Dear Ulrik, > Suppose I wish to draw 2 numbers at random without replacement from vector A > A = [1 2 3 4 5 6 7 8 9 10] > Which command will let me do this in Matlab? See RANDPERM: Permute the vector randomly and draw the first 2 numbers. If you need speed, see: http://www.mathworks.com/matlabcentral/fileexchange/27076 If your A is large, e.g. 1e7 elements, the random permutation wastes a remarkable chunk of time and memory. SHUFFLE in the "index" mode is more efficient: A = rand(1, 1e7); Index = Shuffle(1e7, 'index', 2); B = A(Index) Good luck, Jan
From: Ulrik Nash on 8 Jul 2010 06:08 "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <i1428g$q8d$1(a)fred.mathworks.com>... > Dear Ulrik, > > > Suppose I wish to draw 2 numbers at random without replacement from vector A > > A = [1 2 3 4 5 6 7 8 9 10] > > Which command will let me do this in Matlab? > > See RANDPERM: Permute the vector randomly and draw the first 2 numbers. > > If you need speed, see: > http://www.mathworks.com/matlabcentral/fileexchange/27076 > If your A is large, e.g. 1e7 elements, the random permutation wastes a remarkable chunk of time and memory. SHUFFLE in the "index" mode is more efficient: > A = rand(1, 1e7); > Index = Shuffle(1e7, 'index', 2); > B = A(Index) > > Good luck, Jan Thanks Jan, that was a great help.
|
Pages: 1 Prev: Matrix Binary Help Next: problem with opening MatLab editor |