Create an array of all possible combinations?

13 views (last 30 days)
I have a sensor. The sensor can have one of two possible readings ( Smax or Smin), one of two possible azimuths ( Amax or Amin), and one of two possible elevations ( Emax or Emin). Therefore I have 8 unique combinations.
Suppose I have ( t) total number of sensors. Now I have 8^ t number of unique combinations. I arrange the potential values of each variable into the following matrices:
  • Smax=[tx1]
  • Smin=[tx1]
  • Amax=[1xt]
  • Amin=[1xt]
  • Emax=[1xt]
  • Emin=[1xt]
I created a function f with the input variables S, A, and E. It can return 8^ t number of unique outputs. How do I write a script that will create an array of all the possible unique outputs?

Answers (1)

Star Strider
Star Strider on 5 Feb 2016
One option:
x = nchoosek([1:2 1:2 1:2],3);
perm = unique(x, 'rows')
perm =
1 1 1
1 1 2
1 2 1
1 2 2
2 1 1
2 1 2
2 2 1
2 2 2
  2 Comments
Mahmoud Muhtaseb
Mahmoud Muhtaseb on 5 Feb 2016
Edited: Mahmoud Muhtaseb on 5 Feb 2016
That gives 8 combinations. How do I get 8^t combinations?
Thanks
Star Strider
Star Strider on 5 Feb 2016
For a positive integer ‘t’ and two possibilities for each, this would work:
t = 5;
x = nchoosek(repmat([1 2],1,5),t);
perm = unique(x, 'rows')

Sign in to comment.

Categories

Find more on Creating and Concatenating Matrices 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!