How to calculate the mean of 5 columns in a 12x80x250 array?

6 views (last 30 days)
Hello all, I have a newbie question: I have a 12x80x250 multidimensional array (12 rows, 80 columns, 250 "pages"). What I have to do is to create an 81th column which corresponds to the mean of the columns 8,13,27,45,52. I created a new variable which keeps the first and the third dimension constant and extracts only my 5 columns of interest:
Q=Array(:,([8 13 27 45 52]),:);
Now I have the Q variable which is a 12x5x250 array. In the next step I would like to "squeeze" the 5 columns into a single one containing the average values across them. Then the final step would be to embed this new column into my initial array.Thanks

Accepted Answer

the cyclist
the cyclist on 31 Jul 2019
Edited: the cyclist on 31 Jul 2019
Q=Array(:,([8 13 27 45 52]),:);
QMean = mean(Q,2);
ArrayAndQMean = cat(2,Array,QMean);
You could do it all in a one-liner:
ArrayAndQMean = cat(2,Array,mean(Array(:,([8 13 27 45 52]),:),2));

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Products


Release

R2014b

Community Treasure Hunt

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

Start Hunting!