VBA: Multi-dimensional array sum/mean/stdev

Ells_

Board Regular
Joined
Jan 5, 2014
Messages
56
I have a quick question that I couldn't quite find when searching for it.
I have a 3 dimensional array myArray(x,y,z), with x & y being input and z being output data in my case. I want to use different functions on myArray(x,y,:), where : is all z values. example: cell(x,y) = sum(myArray(x,y,:)). I know I can do this with a (triple) loop, but I was wondering if there was an easier way to do this, since I know you can with 1-dimensional arrays

Thanks
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Is it really a 3D array, or a 2D array (1 to n, 1 to 3)?
 
Upvote 0
Is it really a 3D array, or a 2D array (1 to n, 1 to 3)?

It is a 3D array. The first two dimensions are constant, and 3rd is the data itself. ex: myArray(1,1,data_points). The 3rd dimension is the same for every x and y.
 
Upvote 0
I guess I'm missing what you're doing.

If you have a list of triplets {x,y,z}, you only need a 2D array to store it.

If you had a table with x values across the top, y values down the side, and z values in the body of the table, you would use 1D arrays for x and y, and a 2D array for z.

In any case, none of the worksheet functions will work on 3D arrays.
 
Upvote 0
I guess I'm missing what you're doing.

If you have a list of triplets {x,y,z}, you only need a 2D array to store it.

If you had a table with x values across the top, y values down the side, and z values in the body of the table, you would use 1D arrays for x and y, and a 2D array for z.

In any case, none of the worksheet functions will work on 3D arrays.

I guess I'll reword my description of my problem.
I have a myArray(x,y,z). If I input x and y, it will take the sum/average/stdev of all the z data of that x,y.

myArray(1,3,1) = 1
myArray(1,3,2) = 2
myArray(1,3,3) = 3

sum(myArray(1,3,1:3)) = 6
^ something that has this functionality is what I'm after. I just want to see if there's a way to do it without having to loop through everything
 
Upvote 0
I know of no way other than a loop for 3D arrays. The worksheet functions you might use (e.g., Index, to get a slice of a 2D array) don't work on 3D arrays.
 
Upvote 0

Forum statistics

Threads
1,214,634
Messages
6,120,659
Members
448,975
Latest member
sweeberry

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top