0

I have a problem with certain issue. So, I have a three sets with four elements, e.g.:

[r11, r12, r13, r14]
[r21, r22, r23, r24]
[r31, r32, r33, r34]

I need all combination between these elements. But always each of this elements in particular sets must be in the same place:

1. r11  r21 r31
2. r11  r21 r32
       .
       .
       .
n. r14  r24 r34

How can I do that in Matlab or Mathcad?

Jaumenik
  • 33
  • 6

1 Answers1

0

Assuming sets S1, S2, S3 where S1 is your [r11, r12, r13, r14]:

[A,B,C] = ndgrid(S3, S2, S1);
[C(:), B(:), A(:)]

For example input:

S1 = [1,2];
S2 = [10,20];
S3 = [100,200,300];

results in:

ans =

     1    10   100
     1    10   200
     1    10   300
     1    20   100
     1    20   200
     1    20   300
     2    10   100
     2    10   200
     2    10   300
     2    20   100
     2    20   200
     2    20   300
Dan
  • 45,079
  • 17
  • 88
  • 157
  • @user3770989 I suggest you read through the answers that Amro linked to (i.e. the duplicate), I hadn't seen some of them before. – Dan Jun 27 '14 at 12:32