Please enable JavaScript to view this site.

Knowledge Base

Returns the sum of elements in a matrix.

 

Supported Product: FDTD, MODE, DEVICE, INTERCONNECT

 

Syntax

Description

out = sum(x);

Sum of all the elements in matrix x, over all dimensions.

out = sum(x,n);

Sum elements of x over the specified dimension n.

 

Example

This example shows how you can sum all the elements of a matrix or just the elements over a specified dimension.

?a = [1,2;3,4]; # define a 2x2 matrix

result: 

1 2 

3 4 

 

?sum(a); # sum all elements

result: 

10

 

?sum(a,2); # sum over the second dimension only

result: 

7  

 

See Also

Functions, integrate, mean, prod

Copyright Lumerical Inc. | Privacy | Site Map