Here's one way to sum numbers from 1 to n using a loop in MATLAB:
main.m91 chars7 lines
This function takes a single argument n
and returns the sum of numbers from 1 to n
. It initializes the result to 0, then loops through the numbers from 1 to n and adds each to the result. Finally, it returns the result.
gistlibby LogSnag