0
      20     4     4    74    20    20   74   85  85  85   2    1
 A =  36     1     1    11    36    36   11   66  66  66   4    1
      77     1     1    15    77    77   15   11  11  11   1    4
       3     4     2     6     7     8   10   10  15  17   1    5

      20   4   85
 B =  36   1   66
      77   1   11

How from the matrix A, I can extract the submatrix whose coloumns contains the vectors B(:,i): ​​[20 36 77] , [4 1 1] and [85 66 11]?

The desired result:

      20     4     4    20    20   85  85  85
      36     1     1    36    36   66  66  66
      77     1     1    77    77   11  11  11
       3     4     2     7     8   10  15  17
Stewie Griffin
  • 14,889
  • 11
  • 39
  • 70
bzak
  • 563
  • 1
  • 8
  • 21

1 Answers1

3

Now that you've explained what you want, transpose the matrices, select only the three top rows of A, and then use the third argument of ismember to specify that you want to compare entire rows:

A(:,ismember(A(1:3,:).', B.', 'rows').')

    20     4     4    20    20    85    85    85
    36     1     1    36    36    66    66    66
    77     1     1    77    77    11    11    11
     3     4     2     7     8    10    15    17
Stewie Griffin
  • 14,889
  • 11
  • 39
  • 70