I'm fairly to Matlab / Octave and Machine learning, but so far I've learned you want to avoid iterative loops for summation and vectorize as much as possible.
Given a row vector like: x = [ 1,2,3,4,5]
You can calculate the sum with these two methods:
sum(x)
x * ones(length(x),1)
While my gut tells me to us the built in functions, the second options feels more 'vectorized'.
Which of the is more optimal and why? Are there tradeoffs between the two in performance vs. memory use, etc...?