简洁的想法

仁爱、喜乐、和平、忍耐、恩慈、良善、信实、温柔、节制

Matlab & Magic

| Comments

这次不想说magic(3),

1
2
3
4
5
magic(3)
ans =
     8     1     6
     3     5     7
     4     9     2

外国佬是玩倒立, 还是中国的九宫决看着舒服:
二四为肩,六八为足,左三右七,戴九履一,五居中央.

我想说的是Matlab的Matrix就像Magic:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
>> a = [1:3]'
a =
     1
     2
     3
>> b = a(:,ones(1,4),ones(1,1,5))
b(:,:,1) =
     1     1     1     1
     2     2     2     2
     3     3     3     3
b(:,:,2) =
     1     1     1     1
     2     2     2     2
     3     3     3     3
b(:,:,3) =
     1     1     1     1
     2     2     2     2
     3     3     3     3
b(:,:,4) =
     1     1     1     1
     2     2     2     2
     3     3     3     3
b(:,:,5) =
     1     1     1     1
     2     2     2     2
     3     3     3     3
>> c = permute(b, [2,3,1])
c(:,:,1) =
     1     1     1     1     1
     1     1     1     1     1
     1     1     1     1     1
     1     1     1     1     1
c(:,:,2) =
     2     2     2     2     2
     2     2     2     2     2
     2     2     2     2     2
     2     2     2     2     2
c(:,:,3) =
     3     3     3     3     3
     3     3     3     3     3
     3     3     3     3     3
     3     3     3     3     3

Comments