Using explicit iteration is not the most efficient way of solving this problem, but if you do choose to iterate I would suggest using "linear indexing", per https://au.mathworks.com/help/matlab/math/matrix-indexing.html?s_tid=doc_srchtitle#f1-85511
Project Euler: Problem 6, Natural numbers, squares and sums.
1057 Solvers
530 Solvers
Matrix of almost all zeros, except for main diagonal
156 Solvers
136 Solvers
93 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!