How to find all possible combinations of an array?
3 views (last 30 days)
Show older comments
I am mapping a path that a delivery truck could take, all trips must go to 8 locations.
Location 1 (starting location) and location 8 (ending location) are both the same place and fixed. I am trying to figure out the best way to get all of the random combinations of the other locations, 2 through 7.
0 Comments
Answers (1)
Joseph Cheng
on 1 Mar 2016
Edited: Joseph Cheng
on 1 Mar 2016
the function perms will generate all the combinations
perms(2:7)
will give you
7 6 5 4 3 2
7 6 5 4 2 3
7 6 5 3 4 2
7 6 5 3 2 4
7 6 5 2 3 4
......
2 7 3 6 4 5
2 7 6 4 3 5
2 7 6 4 5 3
2 7 6 3 4 5
2 7 6 3 5 4
2 7 6 5 3 4
2 7 6 5 4 3
2 Comments
Walter Roberson
on 1 Mar 2016
Note that the number of such permutations grows quickly with the size of the number of elements, so this technique is seldom used for traveling salesman problems.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!