How to select a submatrix (not in any particular pattern) in Matlab

前端 未结 3 1137
悲&欢浪女
悲&欢浪女 2020-11-27 04:45

How to select a submatrix (not in any pattern) in Matlab? For example, for a matrix of size 10 by 10, how to select the submatrix consisting of intersection of the 1st 2nd a

3条回答
  •  忘掉有多难
    2020-11-27 05:21

    Let me explain with an example:

    Let's define a 6x6 matrix

    A = magic(6)
    
    A = 
    35     1     6    26    19    24
     3    32     7    21    23    25
    31     9     2    22    27    20
     8    28    33    17    10    15
    30     5    34    12    14    16
     4    36    29    13    18    11
    

    From this matrix you want the elements in rows 1, 2 and 5, and in the columns 4 and 6

    B = A([1 2 5],[4 6])
    
    B = 
    
    26    24
    21    25
    12    16
    

    Hope this helps.

提交回复
热议问题