Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: nchoosek all pairwise combinations
Replies: 10   Last Post: Nov 27, 2012 7:46 AM

 Messages: [ Previous | Next ]
 Jos Posts: 1,268 Registered: 10/24/08
Re: nchoosek all pairwise combinations
Posted: Nov 27, 2012 7:46 AM

"Nasser M. Abbasi" <nma@12000.org> wrote in message <k925db\$3ms\$1@speranza.aioe.org>...
> On 11/27/2012 4:37 AM, Jos (10584) wrote:
> > "Nasser M. Abbasi" <nma@12000.org> wrote in message
> >> Nice. I did not know about cellstr. That is definitly
> >> better. 2 lines shorter than mine :)

> >
> > ... but your code uses my function ALLCOMB which gives you lots of credits ;-)
> >

>
> I had harder time since I did not know about cellstr.
>
> Using cellstr, now it is like this (with the use of allcomb (nice function))
>
> ------------------------------
> A=['a', 'b', 'c', 'd','e']; N=size(A,2);
> reshape(cellstr(A(allcomb(1:N,1:N))),N,N)
> --------------------------------
>
> 'aa' 'ba' 'ca' 'da' 'ea'
> 'ab' 'bb' 'cb' 'db' 'eb'
> 'ac' 'bc' 'cc' 'dc' 'ec'
> 'ad' 'bd' 'cd' 'dd' 'ed'
> 'ae' 'be' 'ce' 'de' 'ee'
>
> I dont know how I overlooked cellstr. Very useful.
>
>
> --Nasser
>
>

Note that ALLCOMB and its sibling COMBN are "clever" wrappers around NDGRID.

~ Jos

Date Subject Author
11/26/12 Jerry
11/27/12 Nasser Abbasi
11/27/12 Nasser Abbasi
11/27/12 Nasser Abbasi
11/27/12 Jos
11/27/12 Nasser Abbasi
11/27/12 Jos
11/27/12 Nasser Abbasi
11/27/12 Jos
11/27/12 Nasser Abbasi
11/27/12 Jos