problem with array function
Find bottlenecks in your Excel workbooks
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 2 of 2

Thread: problem with array function

  1. #1
    Board Regular
    Join Date
    Mar 2002
    Posts
    76
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    I am trying to convert a lower diagonal matrix to a symmetric matrix using the following simple function. It works great for matrix of size 60X60 for sure, I tried using it for 120X120 matrix and it failed.
    Is there something I am doing wrong!

    Here is the function code!


    Function fullmatrix(matrix) As Variant
    Set therange = matrix
    nrows = matrix.Rows.Count
    ReDim matrix(1 To nrows, 1 To nrows) As Double
    Dim outp1() As Double
    ReDim outp1(1 To nrows, 1 To nrows)
    For i = 1 To nrows
    For j = 1 To i
    outp1(i, j) = therange.Cells(i, j)
    Next
    Next
    For j = 1 To nrows
    For i = j + 1 To nrows
    outp1(j, i) = outp1(i, j)
    Next
    Next

    End If

    fullmatrix = outp1()
    End Function

  2. #2
    Board Regular
    Join Date
    Mar 2002
    Posts
    76
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    Sorry, there is no end if!
    Corrected code here...

    I am trying to convert a lower diagonal matrix to a symmetric matrix using the following simple function. It works great for matrix of size 60X60 for sure, I tried using it for 120X120 matrix and it failed.
    Is there something I am doing wrong!

    Here is the function code!


    Function fullmatrix(matrix) As Variant
    Set therange = matrix
    nrows = matrix.Rows.Count
    ReDim matrix(1 To nrows, 1 To nrows) As Double
    Dim outp1() As Double
    ReDim outp1(1 To nrows, 1 To nrows)
    For i = 1 To nrows
    For j = 1 To i
    outp1(i, j) = therange.Cells(i, j)
    Next
    Next
    For j = 1 To nrows
    For i = j + 1 To nrows
    outp1(j, i) = outp1(i, j)
    Next
    Next



    fullmatrix = outp1()
    End Function

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com