主要内容

sum

Return sum of elements in DataMatrix object

Description

S = sum(DMObj) returns the sum of the elements in the columns of a DataMatrix object, treating NaNs as missing values. S is a row vector containing the sums of the elements in each column in DMObj.

example

S = sum(DMObj,Dim) returns the sum of the elements in the columns or rows of DMObj, as specified by the dimension Dim.

example

S = sum(DMObj, Dim, IgnoreNaN) specifies whether to ignore NaN values.

Examples

collapse all

Create a DataMatrix object.

dm = bioma.data.DataMatrix([2,3;4,5;6,7]);

Compute the sum of the elements along the columns of DataMatrix.

SC = sum(dm)
SC = 1×2

    12    15

Compute the sum of elements along the rows.

SR = sum(dm,2)
SR = 3×1

     5
     9
    13

Input Arguments

collapse all

DataMatrix object, specified as a bioma.data.DataMatrix object.

Dimension of DataMatrix to return the sum of elements for, specified as 1 or 2.

If Dim = 1, the function returns the sums of the elements in each column in DMObj. If Dim = 2, the function returns the sums of the elements in each row in DMObj.

Flag to ignore NaN values, specified as a numeric or logical 1 (true) or 0 (false).

Data Types: logical

Output Arguments

collapse all

Sum of elements in DataMatrix, returned as a numeric scalar or vector.

If the values in DMObj are single, then S is a single; otherwise, S is a double.

Data Types: single | double

Version History

Introduced in R2008b

See Also

| |