Permutation of variables with different states - get all combinations

1 次查看(过去 30 天)
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 ? :)

回答(1 个)

Stephen23
Stephen23 2018-8-24
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

类别

Help CenterFile Exchange 中查找有关 Line Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by