MATLAB: Collapse across dimensions of a matrix

MATLABmatrix operationsmeanmulti-dimensionsal

I have a multidimensional matrix 19 x 64 x 5 x 21 which corresponds to 19 participants x 64 channels x 5 timepoints x 21 data values.
I want to collapse the last two dimensions of the matrix so that I end up with the mean of the (5 x 21) data values, per participant, per channel (i.e. a 19 x 64 (x1) matrix)
I've tried using mean, tried using reshape etc but I am really struggling with the scale of the data and picturing how the the four dimensions fit together. As such I can't confidently manipulate the data across the four dimensions so any guidance would be appreciated.

Best Answer

If you're using release R2018b or later, several data analysis functions (including mean) can accept a vector of dimensions over which to operate. See the Release Notes for a list of which functions can accept a vector of dimensions.