How to calculate the mean of 5 columns in a 12x80x250 array?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
mimmo voso
am 31 Jul. 2019
Kommentiert: mimmo voso
am 31 Jul. 2019
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
0 Kommentare
Akzeptierte Antwort
the cyclist
am 31 Jul. 2019
Bearbeitet: the cyclist
am 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));
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!