nonzeros
Column vector with the nonzero elements of an array.
Category: Mathematics > Sparse Matrices
Syntax
v = nonzeros(A)
Returns the nonzero values of A, scanning column by column.
Description
The values are collected down the first column, then the second, and so on, which is the order in which a sparse matrix stores them. The positions are lost; to get them as well use find.
Input arguments
A- Numeric or logical array, sparse or full.
Output arguments
v- Column vector with
nnz(A)elements, in column-major order.
Example
Nonzeros in column order
A = [0 5; 6 0; 7 8];
nonzeros(A)
nonzeros(sparse(A))'
Output
ans = 4×1
6
7
5
8
ans = 1×4
6 7 5 8