In some cases, you need to index the summation of elements in a matrix or vector in Matlab to use them in further calculations. This process is very easy in Matlan that you can use ‘sum()’ command in that way. In here, we explain how to calculate summation of all elements of matrices and vectors in Matlab with ‘sum()’ command, easily.

As you see above, a vector is created and a matrix created. Their names are ‘a’ and ‘b’ respectively, as shown in red box above.

The summation of all elements of a vector is basically done with sum() command. You just need to type the a vector inside sum() command, then you can equate this to an another variable as shown by green arrow above.

If you type the matrix variable inside sum() command, you will calculate the summation of all columns in that matrix. If you look ay the variable ‘y’ inside blue box above, you can see that, ‘y’ has 4 elements. Each elements represents the summation of each columns of matrix ‘b’.

YOU CAN LEARN MatLab IN MECHANICAL BASE; Click And Start To Learn MatLab!

If you want to calculate the summation of all the elements of a matrix, you need to type the summatiıon of each column inside sum() command. As you see above this is done as shown by green arrow, for variable ‘z’. The variable ‘z’ gives the summation of all elements of a matrix.

As you see above the use of ‘sum()’ command in Matlab is very simple. Do not forget to leave your comments and questions about sum() command in Matlab below.

Download And Install MatLab R19!

Your precious feedbacks are very important for us.

There are no comments for this article yet! You can make the first comment.