No BSD License  

Highlights from
pickn

2.0

2.0 | 2 ratings Rate this file 4 Downloads (last 30 days) File Size: 1.91 KB File ID: #3423

pickn

by Richard Medlock

 

10 May 2003 (Updated 19 May 2003)

Return P random picks of N items from an input vector A.

| Watch this File

File Information
Description

B = PICKN(A,N,P)

Returns P random Picks of N items from vector A.

PickN assumes that each item can be repelaced after selection.

Example:
  A list contains four elements: [1 2 3 4]
  Show two possible combinations of choosing 3 items
  from the list.

A = [1:4];
N = 3;
P = 2;

B = pickn(A,N,P)

      1 3 1
      2 4 1

If you specifcy P as the string 'all', then B will contain
all possible permutations.

MATLAB release MATLAB 6.5 (R13)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
20 Feb 2006 Matthias Wetzel  
04 Oct 2007 Jos x@y.z

B = A(ceil(numel(A)*rand(P,N))) ;
would do the job much (much!!) faster.
Creating all possible combinations first is very time- and memory consuming ... The retrieval of all combinations of elements is handled much more efficient by other contributions here (search the FEX for "combinations")

14 Aug 2009 Richard Medlock

Hi, thanks for your feedback. This file was written well over 4 years ago (before you reviewed it) and at the time there was nothing available that did this. As with all my files they were simple (in my mind) solutions to achieve what I wanted and worked. I posted them in case anyone else found them useful. Perhaps you might consider that in future when rating (very!!) old submissions ;-)

Please login to add a comment or rating.
Updates
19 May 2003

Typo. 3rd arg was supposed to be P not C. If you have already downloaded the previous version, please change it to P, otherwise there is now a new version available.

19 May 2003

Typo. 3rd arg was supposed to be P not C. If you have already downloaded the previous version, please change it to P, otherwise there is now a new version available.

Tag Activity for this File
Tag Applied By Date/Time
statistics Richard Medlock 22 Oct 2008 07:01:30
probability Richard Medlock 22 Oct 2008 07:01:30
pick Richard Medlock 22 Oct 2008 07:01:30
choose Richard Medlock 22 Oct 2008 07:01:30
permute Richard Medlock 22 Oct 2008 07:01:30
permutation Richard Medlock 22 Oct 2008 07:01:30
selection Richard Medlock 22 Oct 2008 07:01:30
random Richard Medlock 22 Oct 2008 07:01:30

Contact us at files@mathworks.com