How to obtain all possible combinations of cell array?
4 views (last 30 days)
Show older comments
I have a cell array {'One','Two','Three','Four','Five'} I need to obtain all possible combinations with 2 and with 3 elements from this array. Like this:
One Two
One Three
...
Three one
Three Two
...
Four One
Four Two ...
And so on, mixing also the order. I need it with two elements and with three of this cell array, how is it posible to do so?
thank you!
0 Comments
Answers (1)
Star Strider
on 9 Apr 2017
6 Comments
Star Strider
on 9 Apr 2017
I decided to just ‘brute force’ it:
for k1 = 1:500
combs3(k1,:) = randperm(5,3);
end
combs3 = unique(combs3, 'rows')
combs3 =
1 2 3
1 2 4
1 2 5
1 3 2
1 3 4
1 3 5
1 4 2
1 4 3
1 4 5
1 5 2
1 5 3
1 5 4
2 1 3
2 1 4
2 1 5
2 3 1
2 3 4
2 3 5
2 4 1
2 4 3
2 4 5
2 5 1
2 5 3
2 5 4
3 1 2
3 1 4
3 1 5
3 2 1
3 2 4
3 2 5
3 4 1
3 4 2
3 4 5
3 5 1
3 5 2
3 5 4
4 1 2
4 1 3
4 1 5
4 2 1
4 2 3
4 2 5
4 3 1
4 3 2
4 3 5
4 5 1
4 5 2
4 5 3
5 1 2
5 1 3
5 1 4
5 2 1
5 2 3
5 2 4
5 3 1
5 3 2
5 3 4
5 4 1
5 4 2
5 4 3
See Also
Categories
Find more on Discrete Math in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!