2017-07-07 53 views
0

我將使用下面的公式上的4×6每個小區(m×n箇中的代碼)矩陣,以獲得歸一化的矩陣:
\pi_{ij}=\frac{x_{ij}}{\sqrt{\Sigma_{i=1}^m x_{ij}^2}}使用LibreOffice的基本(LibreOffice的計算值)的矩陣工作

在Calc中的矩陣是:
enter image description here

我用的LibreOffice以下基本代碼:

REM ***** BASIC ***** 

Sub Main 

Normalize(5,3) 

End Sub 



Sub Normalize (ByVal n As Integer,ByVal m As Integer) 

Dim Doc As Object 
Dim Sheet As Object 
Dim SrcCell 'Cell in the source matrix 
Dim TargetCell 'Cell in the target matrix where normalized values are saved 
Dim TempCell As Object 

Dim I 'index 
Dim J 'index 
Dim JJ 'inner index 
Dim Sum 'Sigma x_ij^2 (j=0 to m) 
Dim m 'maximum row index 
Dim n 'maximum column index 


Doc = ThisComponent 
Sheet = Doc.Sheets(0) 




For I = 0 to n 'traverse columns 
    For J=0 to m 'traverse rows 
     SrcCell = Sheet.getCellByPosition(I,J) 
     'Now apply the normalization formula for this cell 
     'Run a new loop to run formula on this cell 
     Sum = 0 'Reset Sum to 0 
     For JJ=0 to m 
      TempCell = Sheet.getCellByPosition(I,JJ) 
      Sum = Sum + (TempCell.Value^2) 
     Next 
     TargetCell = Sheet.getCellByPosition(I+n+1,J) 'Place the normalized cells in a new matrix cell, n+1 cells away 

     'Put the sum in the formula 
     TargetCell.Value = SrcCell.Value/Sqr(Sum) 

    Next 


Next 

End Sub 

我想要將標準化的矩陣出現在原始矩陣的右側。但沒有出現。我究竟做錯了什麼?

回答

0

該代碼使用nm作爲參數,但隨後聲明它們,銷燬值。要修復,請刪除以下兩行。爲了便於閱讀,請將這些評論移至Sub Normalize附近。

Dim m 'maximum row index 
Dim n 'maximum column index 

到工具欄,設置幾個斷點在發現這種問題基本IDE調試器,按斷點開/關,也使觀看。