Hi everyone. I have an interesting situation. So the idea is to calculate the value of middle points of a 1D, 2D or 3D matrix.
For example, A is a 100*100 matrix. What I want to obtain is an 99*99 matrix which simply represent the averaged value of the 3D matrix A.
I could easily do it by following:
B = (A(2:end,2:end)+A(2:end,1:end-1)+A(1:end-1,2:end)+A(1:end-1,1:end-1))/4;
However, this is rather slow as I need to reference A by 4 times. The situation is worse for 3D or large A. I am just wondering if there is a faster way to do this task by avoiding the multiple referencing or if there is any build-in matlab function that could do it in a faster way?
Thank you very much!