Exact permutation or combination

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Karen Amanda
    New Member
    • Oct 2006
    • 3

    #1

    Exact permutation or combination

    I need help programming in Visual Basic 6.3 in Excel.
    Here is what I am trying to do:
    I have an array with x rows and y columns: Exact(x,y). I want to select all possible combinations of one cell from each row and then calculate the average. In other words, a value of y for each x. For example if there are 3 rows and 4 columns, the combinations would be:
    1 1 1 (1st cell from row 1, 1st cell from row 2, 1st cell from row 3)
    1 1 2
    1 1 3
    1 1 4
    1 2 1
    1 2 2
    1 2 3
    ...
    4 4 4
    I have been working with Visual Basic for several years and I am familiar with the basic functions (If Then, For Next etc.) and I can work out some other functions, but my expertise is not very advanced.
    I would appreciate any suggestions.
    Thanks.
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Originally posted by Karen Amanda
    I need help programming in Visual Basic 6.3 in Excel.
    Here is what I am trying to do:
    I have an array with x rows and y columns: Exact(x,y). I want to select all possible combinations of one cell from each row and then calculate the average. In other words, a value of y for each x. For example if there are 3 rows and 4 columns, the combinations would be:
    1 1 1 (1st cell from row 1, 1st cell from row 2, 1st cell from row 3)
    1 1 2
    1 1 3
    1 1 4
    1 2 1
    1 2 2
    1 2 3
    ...
    4 4 4
    I have been working with Visual Basic for several years and I am familiar with the basic functions (If Then, For Next etc.) and I can work out some other functions, but my expertise is not very advanced.
    I would appreciate any suggestions.
    Thanks.
    Can you tell us if this is what you are planning please?

    Iterate through all of the values in a row and find the average value

    or is it

    Iterate through all of the values in all of the rows and find the average value

    Comment

    • Karen Amanda
      New Member
      • Oct 2006
      • 3

      #3
      I need to find all iterations/combinations and calculate the average value for each one. It is part of a randomization program in which I compare an observed average to a set of permuted averages, in this case an exact permutation in which I calculate the average for all possible combinations of the data.


      Originally posted by willakawill
      Can you tell us if this is what you are planning please?

      Iterate through all of the values in a row and find the average value

      or is it

      Iterate through all of the values in all of the rows and find the average value

      Comment

      • willakawill
        Top Contributor
        • Oct 2006
        • 1646

        #4
        Originally posted by Karen Amanda
        I need to find all iterations/combinations and calculate the average value for each one. It is part of a randomization program in which I compare an observed average to a set of permuted averages, in this case an exact permutation in which I calculate the average for all possible combinations of the data.
        This should work:

        Code:
            Dim intRow1 As Integer
            Dim intRow2 As Integer
            Dim intRow3 As Integer
            Dim intAverage As Integer
            
            For intRow1 = LBound(exact, 2) To UBound(exact, 2)
                For intRow2 = LBound(exact, 2) To UBound(exact, 2)
                    For intRow3 = LBound(exact, 2) To UBound(exact, 2)
                        intAverage = (exact(0, intRow1) + exact(1, intRow2) + exact(2, intRow3)) / 3
                        'do what you want with this average here
                    Next intRow3
                Next intRow2
            Next intRow1

        Comment

        • Karen Amanda
          New Member
          • Oct 2006
          • 3

          #5
          Thank-you very much. It gave me the framework I needed to make it work.


          Originally posted by willakawill
          This should work:

          Code:
              Dim intRow1 As Integer
              Dim intRow2 As Integer
              Dim intRow3 As Integer
              Dim intAverage As Integer
              
              For intRow1 = LBound(exact, 2) To UBound(exact, 2)
                  For intRow2 = LBound(exact, 2) To UBound(exact, 2)
                      For intRow3 = LBound(exact, 2) To UBound(exact, 2)
                          intAverage = (exact(0, intRow1) + exact(1, intRow2) + exact(2, intRow3)) / 3
                          'do what you want with this average here
                      Next intRow3
                  Next intRow2
              Next intRow1

          Comment

          Working...