首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用LibreOffice Basic (LibreOffice Calc)处理矩阵

使用LibreOffice Basic (LibreOffice Calc)处理矩阵
EN

Stack Overflow用户
提问于 2017-07-07 08:28:12
回答 1查看 1.2K关注 0票数 0

我将在4×6 (代码中的m×n)矩阵的每个单元上使用以下公式来得到规范化矩阵:

在Calc中的矩阵是:

我在LibreOffice中使用了以下基本代码:

代码语言:javascript
复制
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 

我要让正规化矩阵出现在原始矩阵的右边。但什么也没出现。我做错了什么?

EN

回答 1

Stack Overflow用户

发布于 2017-07-07 09:48:54

代码使用nm作为参数,然后声明它们,销毁值。若要修复,请删除以下两行。为了提高可读性,请将这些注释移到Sub Normalize附近。

代码语言:javascript
复制
Dim m 'maximum row index 
Dim n 'maximum column index

若要查找基本IDE调试器的此类问题,请按工具栏中的断点( On/Off )设置两个断点,并启用Watch。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44966066

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档