Clear Filters
Clear Filters

Permutation of variables with different states - get all combinations

1 view (last 30 days)
Hello guys, I have four IDs:
  1. A
  2. B
  3. C
  4. D
For each ID different states are possible (note, that A/B have different states than C/D):
  1. A [1; 2; 3]
  2. B [1; 2; 3]
  3. C [1; 3; 4]
  4. D [1; 3; 4]
I would like to permutate these states and get all combinations:
A B C D
1 3 4 3
....
How can I do that in matlab ? :)

Answers (1)

Stephen23
Stephen23 on 24 Aug 2018
Download Jos's excellent allcomb, and use it like this:
>> allcomb([1,2,3],[1,2,3],[1,3,4],[1,3,4])
ans =
1 1 1 1
1 1 1 3
1 1 1 4
1 1 3 1
1 1 3 3
1 1 3 4
1 1 4 1
1 1 4 3
1 1 4 4
1 2 1 1
1 2 1 3
1 2 1 4
1 2 3 1
1 2 3 3
1 2 3 4
1 2 4 1
1 2 4 3
1 2 4 4
1 3 1 1
1 3 1 3
1 3 1 4
1 3 3 1
1 3 3 3
1 3 3 4
1 3 4 1
1 3 4 3
1 3 4 4
2 1 1 1
2 1 1 3
2 1 1 4
2 1 3 1
2 1 3 3
2 1 3 4
2 1 4 1
2 1 4 3
2 1 4 4
2 2 1 1
2 2 1 3
2 2 1 4
2 2 3 1
2 2 3 3
2 2 3 4
2 2 4 1
2 2 4 3
2 2 4 4
2 3 1 1
2 3 1 3
2 3 1 4
2 3 3 1
2 3 3 3
2 3 3 4
2 3 4 1
2 3 4 3
2 3 4 4
3 1 1 1
3 1 1 3
3 1 1 4
3 1 3 1
3 1 3 3
3 1 3 4
3 1 4 1
3 1 4 3
3 1 4 4
3 2 1 1
3 2 1 3
3 2 1 4
3 2 3 1
3 2 3 3
3 2 3 4
3 2 4 1
3 2 4 3
3 2 4 4
3 3 1 1
3 3 1 3
3 3 1 4
3 3 3 1
3 3 3 3
3 3 3 4
3 3 4 1
3 3 4 3
3 3 4 4

Categories

Find more on Line Plots 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!