Math Question_ Combination

2 次查看(过去 30 天)
Hi,
Let say i have 10 location. I wana test 3 location at a time.
i think there are 10C3=120 combination.(assuming order of the location is not important).
My question is how do i list all the combination in an array?
For example [1 2 3,1 2 4, 1 2 5 ,. . . . . till the 120th]

采纳的回答

Oleg Komarov
Oleg Komarov 2011-6-28
nchoosek(1:10,3)
  3 个评论
Kyle
Kyle 2011-6-28
:X i dint even know there is such a command.
Oleg Komarov
Oleg Komarov 2011-6-28
There are many valuable contributions on the FEX which cover combinatorics. I personally use combinator.

请先登录,再进行评论。

更多回答(1 个)

Sean de Wolski
Sean de Wolski 2011-6-28
That's a fun little challenge before lunch break:
[xx yy zz] = ndgrid(1:10);
vals = unique(sort([xx(:),yy(:),zz(:)],2),'rows');
vals(any(~diff(vals,1,2),2),:) = [];

类别

Help CenterFile Exchange 中查找有关 Elementary Math 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by