nonzeros
Nonzero matrix elements.
📝Syntax
v = nonzeros(A)
📥Input Arguments
Parameter Description
A numeric, logical, or character array, including sparse numeric and sparse logical matrices.
📤Output Arguments
Parameter Description
v dense column vector containing the nonzero values of A.
📄Description

nonzeros returns the nonzero values of A in column-major order.

For sparse input, the output is a dense column vector containing only values that are actually nonzero. Stored zero values in a sparse matrix are skipped.

The output keeps the value class of A, including single, complex single, logical, and integer inputs.

💡Examples
A = sparse([1 0 2; 0 3 0]);
v = nonzeros(A)
S = sparse([1 2 1 2], [1 1 2 2], single([0 -0 complex(0, 0) complex(0, 2)]), 2, 2, 4);
v = nonzeros(S)
🔗See Also
findsparsennz
🕔Version History
Version Description
2.0.0 initial version
Edit this page on GitHub