I have a 4D matrix A
of size m × n × p × q
. Consider B = A(:,:,1,1)
which is an m × n
matrix. I want to sum all the elements of B
to give a number. I want to do this for all such B
matrices for all A
so finally I will have a p
by q
matrix.
How can i do this without for loops?
As an example for a 3D matrix (for example A
be a 3D matrix) I think this works,
sum(squeeze(sum(A,1)),1)
But I don't know how to do this for a 4D matrix...