'combnk' enumeration of combinations
    9 views (last 30 days)
  
       Show older comments
    
Hi, 
If I use 'combnk' in a all positive region, it gives me all the possible combinations.
>> c = combnk(1:3,2)
c =
     1     2
     1     3
     2     3
However, if I use 'combnk' in a negative-to-positive region, it only gives me one combination.
>> c = combnk(-1:1,3)
c =
    -1     0     1
What I really like to obtain is something below with all the combinations.
  -1  -1  -1
  -1  -1   0
  -1  -1   1
  -1   0  -1
  -1   0   0
  -1   0   1
  -1   1  -1
  -1   1   0
  -1   1   1
   0  -1  -1
   0  -1   0
   0  -1   1
   0   0  -1
   0   0   0
   0   0   1
   0   1  -1
   0   1   0
   0   1   1
   1  -1  -1
   1  -1   0
   1  -1   1
   1   0  -1
   1   0   0
   1   0   1
   1   1  -1
   1   1   0
   1   1   1
How to achieve it? Should I not use 'combnk' but something else instead?
Please can you help?
0 Comments
Accepted Answer
  Stephen23
      
      
 on 7 Jan 2020
        >> [X,Y,Z] = ndgrid([-1,0,1]);
>> M = [Z(:),Y(:),X(:)]
M =
  -1  -1  -1
  -1  -1   0
  -1  -1   1
  -1   0  -1
  -1   0   0
  -1   0   1
  -1   1  -1
  -1   1   0
  -1   1   1
   0  -1  -1
   0  -1   0
   0  -1   1
   0   0  -1
   0   0   0
   0   0   1
   0   1  -1
   0   1   0
   0   1   1
   1  -1  -1
   1  -1   0
   1  -1   1
   1   0  -1
   1   0   0
   1   0   1
   1   1  -1
   1   1   0
   1   1   1
0 Comments
More Answers (0)
See Also
Categories
				Find more on Sources 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!
