MATLAB: Help please why ?

sum

A = [ 1 3 2 6 ; 5 7 7 0 ; -2 6 -2 1 ] ;
j = sum(A(1))
j= 1 why ???

Best Answer

the statement
sum(A(1))
is summing only the first element in A, which is 1.
If you want to sum the first row, it should be
sum(A(1,:))
and if you want to sum the first column, it is
sum (A(:,1))