Assuming that you have a matrix A
and the third column contains the numbers you want to sum, you can use the following code to sum all the numbers in the third column:
main.m57 chars5 lines
Here, we initialize a variable sum
to 0, and then loop through every row in matrix A
using a for loop. In each iteration of the loop, we add the value in the third column of the current row to sum
. Finally, after all the rows have been processed, sum
will contain the sum of all the numbers in the third column of the matrix.
gistlibby LogSnag