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.
>> pick(0:1, 4, 'or')
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, '')
1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
Stefan Stoll (2020). Picking elements from a set (https://www.mathworks.com/matlabcentral/fileexchange/12724-picking-elements-from-a-set), MATLAB Central File Exchange. Retrieved .
God bless you, this is certainly useful for my current project! Thanks :)
very Useful, precisely what i was looking for. i appreciate the flxibility with/without repetition
You help me a lot, this is really exactly what I want
Bless you Stefan,
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! :)
Thanks - very helpful, nice implementation
Great, exactly what I was looking for, thanks!
Just what I needed: there is no function for permutations with replacement in Matlab.
Thank you so much! Great function!
simple but good!!
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.
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.