Consulting

Results 1 to 3 of 3

Thread: Help with calculating Correl from 2-D array

  1. #1

    Help with calculating Correl from 2-D array

    Hi Guys,

    I have a two dimensional array "signals" that is 20 by 200 (roughly).

    I want to calculate the correlation of various columns to each other. For example, I want to calculate the correlation of column 1 to column 2... how do I specify it..?

    I am trying
    Correl = Application.WorksheetFunction.Correl(signals(1), signals(2))


    However this isn't working (presumably because i'm treating it as a 1-D array).. Any ideas?

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Hi there,

    No promises as I am not really understanding Correl, but to pull the columns from the array, I think you can use Application.Index

    Option Explicit
        
    Sub exa()
    Dim aryData
    Dim dblCorrel As Double
        
        aryData = Range("A2:J21").Value
        
        dblCorrel = Application.Correl(Application.Index(aryData, 0, 1), Application.Index(aryData, 0, 3))
        
        MsgBox dblCorrel
    End Sub
    Hope that helps,

    Mark

  3. #3
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    [VBA]MsgBox WorksheetFunction.Correl(Range("Signals").Columns(1), Range("Signals").Columns(2))[/VBA]

Posting Permissions

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