# matlab取子矩阵

>> a=magic(5)

a =

17    24     1     8    15
23     5     7    14    16
4     6    13    20    22
10    12    19    21     3
11    18    25     2     9

>> b=a(1:3,1:3)

b =

17    24     1
23     5     7
4     6    13

>> b=a(1:3,[1 3 5])

b =

17     1    15
23     7    16
4    13    22

>> b=a([1 2 4],[1 3 5])

b =

17     1    15
23     7    16
10    19     3

you can even try:
>> c=randint(3,3,sum(size(a)))+1

c =

10     9     7
5     6     9
5     3     1

>> b=a(c)

b =

18    12     5
11    24    12
11     4    17

where you know matlab count element in matrix column by column, for example, in this 2D 5x5 matrix, a(10)=a(5,2)

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客