MATLAB: How to calculate summary of sub matrix in very large matrix

calculatecodedevelopermatrixsubmatrix

I have very large matrix which can be 1000*1000,how to create fast algorithm which calculates summary of submatrix if I have upper left corner, width and height?
Thanks!

Best Answer

By "summary", I assume you mean "sum". If so, just do
subMatrix = m(topRow:topRow+height-1, leftCol:leftCol+width-1);
theSum = sum(subMatrix(:))
Related Question