Main Content

sumsqr

Sum of squared elements of matrix or matrices

Description

example

[s,n] = sumsqr(x) takes a matrix or cell array of matrices, x, and returns the sum, s, of all squared finite values in x, and the number of finite values, n.

If x does not contain finite values, the sum returned is 0.

Examples

collapse all

This example shows how to calculate the sum of squared elements of a matrix and a cell array using the sumsqr function.

m = sumsqr([1 2;3 4])
m = 30
[m,n] = sumsqr({[1 2; NaN 4], [4 5; 2 3]})
m = 75
n = 7

Input Arguments

collapse all

Input elements, specified as a matrix or cell array of matrices.

Output Arguments

collapse all

Sum of all squared elements in x, returned as a scalar.

Number of finite values in x, returned as a scalar.

Version History

Introduced before R2006a

See Also

| |