* 矩阵转置示例
* 原始矩阵 : 3x4
===========
1
2
3
4
5
6
7
8
9 10 11 12
===========
* 矩阵转置 : 左上角-右下角翻转
===========
1
5
9
2
6 10
3
7 11
4
8 12
===========
* 矩阵逆转置 : 右上角-左下角翻转
===========
12
8
4
11
7
3
10
6
2
9
5
1
===========
Clear
Local gaArray[ 5, 6 ]
? "原始数组 = 5x6 矩阵 : "
=Matrix_Fill(@gaArray)
=Matrix_Show(@gaArray)
Local R1[ 1 ]
&& 任意大于 0 的数
? "转置数组 = 6x5 矩阵 : "
=Matrix_Transpose(@gaArray, @R1)
=Matrix_Show(@R1)
Local R2[ 1 ]
&& 任意大于 0 的数
? "逆转置数组 = 6x5 矩阵 : "
=Matrix_TransposeA(@gaArray, @R2)
=Matrix_Show(@R2)
Function Matrix_Fill(A1)
* 数组赋值(自然数) - Fill array with element numbers
Local nRow, nCol
For nRow = 1 To Alen( A1, 1 )
For nCol = 1 To Alen( A1, 2 )
A1[ nRow, nCol ] = (nRow-1) * Alen( A1, 2 ) + nCol
Endfor
Endfor
Return
Endfunc
Function Matrix_Show(A1)
* 数组显示 - Display array data
Local nRow, nCol
For nRow = 1 To Alen( A1, 1 )
?
For nCol = 1 To Alen( A1, 2 )
?? A1[ nRow, nCol ], " "
Endfor
Endfor
?
Return
Endfunc
Function Matrix_Transpose(A1, R1)
* 矩阵转置/对称矩阵 : 右上角-左下角翻转
* 定义:如果A(I, J)=A(J, I),则 A 是对称矩阵.
Local nRow, nCol
Dimension R1[Alen(A1, 2), Alen(A1, 1)]
For nRow = 1 To Alen( A1, 1 )
For nCol = 1 To Alen( A1, 2 )
R1[nCol, nRow] = A1[nRow, nCol]
Endfor
Endfor
Return
Endfunc
Function Matrix_TransposeA(A1, R1)
* 矩阵逆转置 : 左上角-右下角翻转
* 定义:如果A(I, J)=A(J, I),则 A 是对称矩阵.
Local nRow, nCol, nRowX, nColY
Dimension R1[Alen(A1, 2), Alen(A1, 1)]
nRowX = Alen(A1, 1)
For nRow = 1 To Alen( A1, 1 )
nColY = Alen(A1, 2)
For nCol = 1 To Alen( A1, 2 )
R1[nCol, nRow] = A1[nRowX, nColY]
nColY = nColY - 1
Endfor
nRowX = nRowX - 1
Endfor
Return
Endfunc