Populating Third Dimesion Based on Average of three elements of Third Dimension
I have a 3D array I populate the first and second dimension with rando
numbers (i.e. all rows and columns). I continue doing this into th third element of the third dimension. For the 4th and 5th elements o the third dimsions I only want to populate the rows and columns if certain criteria is met. Otherwise make the value = 0. (1,1,4) = Rnd() if the average of (1,1,1) to (1,1,3) is < .5 . I wan to average across the 3rd dimension for the rows and columns. Thi would be tantamount to averaging specific cells across three differen sheets. How do you do this? Sub Thing() Dim Array1() As Variant Dim X As Integer Dim Y As Integer Dim Z As Integer ReDim Array1(1 To 4, 1 To 3, 1 To 5) 'Populate 4 rows and 3 columns of top 3 layers with random numbers For Z = 1 To 3 For X = 1 To 4 For Y = 1 To 3 Array1(X, Y, Z) = Rnd() Next Y Next X Next Z 'Populuate remaining layers ( 4 and 5 )if the x values in 1-3 element of third dimension Average<.5 For Z = 4 To 5 For X = 1 To 4 For Y = 1 To 3 If .........Then 'Average across Array1(X, Y, Z) = Rnd() Else Array1(X, Y, Z) = 0 Next Y Next X Next -- Message posted from http://www.ExcelForum.com |
Populating Third Dimesion Based on Average of three elements of Third Dimension
Sub Thing()
Dim Array1() As Variant Dim X As Integer Dim Y As Integer Dim Z As Integer Dim tot as Single ReDim Array1(1 To 4, 1 To 3, 1 To 5) 'Populate 4 rows and 3 columns of top 3 layers with random numbers For X = 1 To 4 For Y = 1 To 3 tot = 0 For Z = 1 To 3 Array1(X, Y, Z) = Rnd() tot = tot + array1(X,Y,Z) Next Z if Tot/3 < .5 then array1(x,y,4) = rnd() array1(x,y,5) = "?" ' you didn't say what to set it to else array1(x,y,4) = 0 array1(x,y,5) = 0 End if Next Y Next X End Sub -- Regards, Tom Ogilvy "ExcelMonkey " wrote in message ... I have a 3D array I populate the first and second dimension with random numbers (i.e. all rows and columns). I continue doing this into the third element of the third dimension. For the 4th and 5th elements of the third dimsions I only want to populate the rows and columns if a certain criteria is met. Otherwise make the value = 0. (1,1,4) = Rnd() if the average of (1,1,1) to (1,1,3) is < .5 . I want to average across the 3rd dimension for the rows and columns. This would be tantamount to averaging specific cells across three different sheets. How do you do this? Sub Thing() Dim Array1() As Variant Dim X As Integer Dim Y As Integer Dim Z As Integer ReDim Array1(1 To 4, 1 To 3, 1 To 5) 'Populate 4 rows and 3 columns of top 3 layers with random numbers For Z = 1 To 3 For X = 1 To 4 For Y = 1 To 3 Array1(X, Y, Z) = Rnd() Next Y Next X Next Z 'Populuate remaining layers ( 4 and 5 )if the x values in 1-3 elements of third dimension Average<.5 For Z = 4 To 5 For X = 1 To 4 For Y = 1 To 3 If .........Then 'Average across Array1(X, Y, Z) = Rnd() Else Array1(X, Y, Z) = 0 Next Y Next X Next Z --- Message posted from http://www.ExcelForum.com/ |
All times are GMT +1. The time now is 11:18 PM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com