Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
nchoosek [Combinatorics]

Subject: nchoosek [Combinatorics]

From: Jerry

Date: 23 Nov, 2012 14:34:08

Message: 1 of 4

Hello,

I am using "nchoosek" to create all possible combinations of four things taken 3 at a time. See below:

nchoosek(['a';'b';'c';'d'],3)
ans =

abc
abd
acd
bcd

However, I would like to modify "nchoosek" or using another function to add following combinations to the above answer.

aaa
bbb
ccc
ddd

Thanks,
Jerry

Subject: nchoosek [Combinatorics]

From: Nasser M. Abbasi

Date: 23 Nov, 2012 14:58:56

Message: 2 of 4

On 11/23/2012 8:34 AM, Jerry wrote:
> Hello,
>
> I am using "nchoosek" to create all possible combinations of four things taken 3 at a time. See below:
>
> nchoosek(['a';'b';'c';'d'],3)
> ans =
>
> abc
> abd
> acd
> bcd
>
> However, I would like to modify "nchoosek" or using another function to add following combinations to the above answer.
>
> aaa
> bbb
> ccc
> ddd
>
> Thanks,
> Jerry
>

is it ok to just add them?

--------------------
L = ['a';'b';'c';'d'];
N = 3;
r = [nchoosek(L,N) ; repmat(L,1,N)]
---------------------

abc
abd
acd
bcd
aaa
bbb
ccc
ddd

--Nasser

Subject: nchoosek [Combinatorics]

From: Steven_Lord

Date: 27 Nov, 2012 17:35:20

Message: 3 of 4



"Jerry " <jerrycholo@gmail.com> wrote in message
news:k8o1h0$lo6$1@newscl01ah.mathworks.com...
> Hello,
>
> I am using "nchoosek" to create all possible combinations of four things
> taken 3 at a time. See below:
>
> nchoosek(['a';'b';'c';'d'],3)
> ans =
>
> abc
> abd
> acd
> bcd
>
> However, I would like to modify "nchoosek" or using another function to
> add following combinations to the above answer.
>
> aaa
> bbb
> ccc
> ddd

Do you also want to allow:

aab
bcc % etc

for all 4^3 combinations? If so look at NDGRID. If you want to add just the
four combinations where each element is the same, Nasser's REPMAT suggestion
is pretty easy.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: nchoosek [Combinatorics]

From: Jos (10584)

Date: 28 Nov, 2012 14:17:19

Message: 4 of 4

"Jerry " <jerrycholo@gmail.com> wrote in message <k8o1h0$lo6$1@newscl01ah.mathworks.com>...
> Hello,
>
> I am using "nchoosek" to create all possible combinations of four things taken 3 at a time. See below:
>
> nchoosek(['a';'b';'c';'d'],3)
> ans =
>
> abc
> abd
> acd
> bcd
>
> However, I would like to modify "nchoosek" or using another function to add following combinations to the above answer.
>
> aaa
> bbb
> ccc
> ddd
>
> Thanks,
> Jerry

See my COMBN function:
http://www.mathworks.com/matlabcentral/fileexchange/7147

~ Jos

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us