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 ]
 Nasser Abbasi Posts: 6,677 Registered: 2/7/05
Re: nchoosek all pairwise combinations
Posted: Nov 27, 2012 3:40 AM

On 11/26/2012 10:12 PM, Jerry wrote:
> 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"?
>

can't you just make a loop?

---------------------
clear all
A = ['a', 'b', 'c', 'd','e'];
N = size(A,2);
B = cell(N);

for i = 1:N
for j = 1:N
B(i,j) = {strcat(A(j),A(i))};
end
end
--------------------

B =

'aa' 'ba' 'ca' 'da' 'ea'
'ab' 'bb' 'cb' 'db' 'eb'
'ac' 'bc' 'cc' 'dc' 'ec'
'ae' 'be' 'ce' 'de' 'ee'

--Nasser

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