Can Sum. If a is a matrix then sum a returns a row vector containing the sum of each column. In mathematics summation is the addition of a sequence of any kind of numbers called addends or summands.
This dimension becomes 1 while the sizes of all other dimensions remain the same. If a is a vector then sum a returns the sum of the elements. Which the summed value as obtained in example 1 and example 2.
If a is a multidimensional array then sum a operates along the first array dimension whose size does not equal 1 treating the elements as vectors.
If a is a vector then sum a returns the sum of the elements. This behaves similarly to the dsum function in microsoft excel. But sometimes you might be working with data sets that are hundreds if not thousands of lines. Which the summed value as obtained in example 1 and example 2.