matlab - Summing unknown number of vectors -
I have two types of matrix & amp; Say size 2000x2 The number of columns in the matrix may vary from 2 to 20. The number of rows will also be different. What I would like to do is add all the columns of matrix into a vector. How can I do this with looping through all the columns?
I have tried the line given below, though if there are two columns or a 3 x 1 vector, the column etc. So it just takes the sum of the total columns.
result_vec = sum (my_matrix (, 1: end)) column 1 column 2 column 3 result vector 5 3 2 10 3 11 4 18 9 6 7 22
To get the line amount, you have to summarize on the other dimension.
Total (my_matrix, 2)
Comments
Post a Comment