Jos
Posts:
1,267
Registered:
10/24/08


Re: nchoosek all pairwise combinations
Posted:
Nov 27, 2012 4:40 AM


"Jerry " <jerrycholo@gmail.com> wrote in message <k91ej5$bp5$1@newscl01ah.mathworks.com>... > Hello, > > There is a vector > > A=['a', 'b', 'c', 'd','e'] > > I would like to make a square matrix of all paiwise interactions of this vector: > > > a b c d e > a aa ba ca da ea > b ab bb cb db eb > c ac bc cc dc ec > d ad bd cd dd ed > e ae bd ce de ee > > However, nchoosek allow me to create only half of this matrix. Is there any function to make all these possible interactions within "A"? > > Thanks, > Jerry
There are many ways to achieve such a matrix, but you should think about how you would store your data. Do you really want a character matrix?
A very easy way to obtain the interactions would be using NDGRID
A = 'abcde' [B1, B2] = ndgrid(A)
which stores the interactions in two separate yet related matrices ... It all depends on what you want to do with the result!
~ Jos

