How would I write code to sum all of the elements of any vector (ie a generic functions which can be applied to any vector) using a for loop? Here is what I have tried and I am stuck because there is an error in line 5 (for X).
My code:
function S = mySum(X)%MYSUM Sum of elements
% S = MYSUM(X) is the sum of the elements of the vector
adder = 0for X adder = adder + Xend S = adder + X
Best Answer