No BSD License  

5.0

5.0 | 11 ratings Rate this file 17 Downloads (last 30 days) File Size: 3.83 KB File ID: #12724

Picking elements from a set

by

 

20 Oct 2006 (Updated )

Gives all possibilities of picking k elements from a set of N with/without order/repetition.

| Watch this File

File Information
Description

s = pick(V,k,Type)

Gives all possibilities of picking k elements from the set V with or without order and repetition.
V can be an array of any size and any type.
Type can have the following values: '', 'o', 'r', 'or'. 'o' means pick ordered list, 'r' means replace elements after picking.

s is an array with all picks, one per row.

Examples:

>> pick(0:1, 4, 'or')
ans =
     0 0 0 0
     0 0 0 1
     0 0 1 0
     0 0 1 1
     0 1 0 0
     0 1 0 1
     0 1 1 0
     0 1 1 1
     1 0 0 0
     1 0 0 1
     ...

>> pick('abcd', 2, '')
ans =
ab
ac
ad
bc
bd
cd

>> pick(1:3,3,'o')
ans =
     1 2 3
     1 3 2
     2 1 3
     2 3 1
     3 1 2
     3 2 1

Acknowledgements

This file inspired V Choose K, V Choose Kr, and V Choose Ko.

MATLAB release MATLAB 7 (R14)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (13)
24 May 2014 JP  
05 Dec 2011 Omar  
20 May 2009 Michele Colombo

very Useful, precisely what i was looking for. i appreciate the flxibility with/without repetition

11 Aug 2008 Adam Wu

You help me a lot, this is really exactly what I want

28 Jul 2008 N. Al-Azri

Bless you Stefan,

18 Jul 2008 Ilya Kuprov

You'd never guess what I use it for -- my spectroscopists are unsure about the signal assignment, so I have to scan the entire assgnment space just in case! :)

15 Jul 2008 Ryan held

Thanks - very helpful, nice implementation

22 May 2008 Jan Peters

Great, exactly what I was looking for, thanks!

10 Mar 2008 Dag Lyberg

Just what I needed: there is no function for permutations with replacement in Matlab.

05 Mar 2008 Morris Z

Thank you so much! Great function!

21 Jun 2007 Uwe Friederich

simple but good!!

06 Nov 2006 Stefan stefan.stoll@ethz.ch

PICK adds the following compared to NCHOOSEK + COMBN:
- ordered list without repeating elements
- unordered list with repeating elements
- a common interface to all four "picking problems"

PICK(V,N,'or') is faster than COMBN(V,N)
for larger V and N. COMBN(V,N) is faster
for small V and N.

23 Oct 2006 Jos NOjos@SPAMjasen.nl

What does this add to nchoosek(V,N) (in Matlab) and combn(V,N) (here on the FEX)? (may be in combination with a sort for ordered lists).
At least this submission is much slower.

Contact us