How to use sum(A, vecdim) In MATLAB
This function is used to sum the elements of A based on the dimensions specified in the vector vecdim.
Example:
Matlab
% MATLAB code for sum(A,'vecdim') % Initializing an array A A = [1 3 5; 2 4 6; 7 9 11; 8 10 12; 13 14 15] % Calling the sum() function % over the above array along % vecdim of [2, 3] Sum = sum(A, [2, 3]) |
Output:
A = 1 3 5 2 4 6 7 9 11 8 10 12 13 14 15 Sum = 9 12 27 30 42
How to find sum of elements of an array in MATLAB?
This article will discuss the “Finding sum of elements of an array” in MATLAB that can be done using multiple approaches which are illustrated below.