fold
Combine (fold) vector elements using function
Description
folds the elements of y = fold(fun,x)x by using fun. That
is, fold applies the function fun on the
first two elements of x, and then recursively applies
fun on the result and the next element until the last
element is combined. Programmatically, this syntax is equivalent to
fold(fun,x) = fun(fold(fun,x(1:end-1)),x(end)).