Clear Filters
Clear Filters

How to calculate the mean along a matrix dimension, but using a variable range, without using a loop?

1 view (last 30 days)
I have a matrix A of dimensions (i=80,j=50,k=40,t=12), where the first two dimensions represent longitude and latitude, the third, depth, and the fourth, time. I also have an integer vector v of size 1x12. How can I obtain a matrix of size (80,50,12), by averaging A along its third dimension, but for each t, the range used to compute the mean is given by 1:v(t)?
That is, how can I calculate the mean of A(:, :, 1:v(t),t), along the third dimension, without using a loop? Is it possible to generalize this for matrices of different sizes?

Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!