| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 711 人关注过本帖
标题:转置矩阵的编程问题
只看楼主 加入收藏
xiaolaba3330
Rank: 1
来 自:辽宁大连
等 级:新手上路
帖 子:175
专家分:0
注 册:2007-10-19
结帖率:100%
收藏
 问题点数:0 回复次数:2 
转置矩阵的编程问题
Dim a(1 To 8, 1 To 8) As Integer, b(1 To 8, 1 To 8) As Integer

Private Sub Command1_Click()
For i = 1 To 8
For j = 1 To 8
b(j, i) = GetArray(a(i, j))
Next
Next
Picture1.CurrentY = 80
For i = 1 To 8
For j = 1 To 8
Picture1.Print Format(b(i, j), "@@@");
Next
Picture1.Print
Picture1.Print
Next
End Sub

Private Sub Form_Activate()
Form_Load
End Sub

Private Sub Form_Load()
k = 0
For i = 1 To 8
For j = 1 To 8
a(i, j) = j + k
Next
k = k + 8
Next
Picture1.CurrentY = 80
For i = 1 To 8
For j = 1 To 8
Picture1.Print Format(a(i, j), "@@@");
Next
Picture1.Print
Picture1.Print
Next
End Sub
Private Function GetArray(m()) As Integer()
Dim L As Integer
Dim U As Integer
L = LBound(m())
U = UBound(m())
ReDim n(U, L)
For i = 1 To U
  For j = 1 To L
   n(j, i) = m(i, j)
   Next
   Next
   GetArray = n
End Function

我写了个程序 但是在b(j, i) = GetArray(a(i, j))这句出错了 怎么改啊?
 希望高手们就以我这个程序为框架,帮我改改!!
搜索更多相关主题的帖子: 矩阵 
2008-04-16 11:18
永夜的极光
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:2721
专家分:1
注 册:2007-10-9
收藏
得分:0 
你的GetArray函数的功能应该是根据传入的i和j,返回a(i,j)的值,所以你应该改成这样
Private Function GetArray(i as integer,j as integer) As Integer
   GetArray = a(i,j)
End Function
调用的时候,也应该改为
b(j, i) = GetArray(i,j)


另,对于二维数组,lbound和ubound如果只用一个参数,只能取得第一维的程度,要取得第二维,要用LBound(m,2)

还有,redim会清除整个数组的内容

从BFS(Breadth First Study)到DFS(Depth First Study)
2008-04-16 11:28
xiaolaba3330
Rank: 1
来 自:辽宁大连
等 级:新手上路
帖 子:175
专家分:0
注 册:2007-10-19
收藏
得分:0 
OK 我在试下,谢谢!!!

编程学习中~~
2008-04-16 11:36
快速回复:转置矩阵的编程问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.034685 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved