but we are not summing all elements in the matrix. If we say, for example sum(sum(X(:,:))), then we sum all elements. I think the original question demands that we sum only subset of the matrix (i=1:100, j=1:5). Thus, even when Xij is 200x200 we only sum the elements in the small given domain. The example I gave was for a small matrix.
The answers of Baraka Maiseli provide the best solution. Remember that loops are interpreted but the builtin functions are most often written in Fortran or C and are thus much faster than your "for" and "while" loops. You should use matrix arithmetic whenever possible. The only case when you need your own loop for summation is if you have a few large elements and many small elements In such a case you have to sort the numbers and sum them in ascending order otherwise you will get roundoff errors. However, this is an extreme case. Consire you have to sum a few numbers as great as 10^16 and about 10^15 numbers close to 1.
B. RADI, A. EL HAMI, Mathématique numérique pour l’ingénieur, Utilisation de MATLAB: Cours, exercices et problèmes de synthèse corrigés. Editions-Ellipses, Numéro ISBN 978-2-7298-5279-5, Novembre 2010 (240 pages, niveau second cycle)