Accessing order pair from sparse matrix

4 views (last 30 days)
Hello, my question has to do with accessing the indicies of a sparse matrix. Say we define $S=sparse(M)$, then if we put S in the command lines we'd see something like this (for example):
(1,3) 5
(2,4) 1
(2,5) 3.1415
Is there a way to just access the order pairs directly? I have two matricies with corresponding elements and want to perfome some tests around the nonzero elements of a figure I am working on. This alone would greatly simplified my code but I can not find any documentation on it...

Accepted Answer

Jan on 27 Mar 2021
Edited: Jan on 27 Mar 2021
Do you want to get the indices of the non-zero elements?
[i,j,s] = find(S);
The is taken from
help sparse
  1 Comment
Marcus Rosales
Marcus Rosales on 27 Mar 2021
Yes! This'll make my code much faster. Thanks!

Sign in to comment.

More Answers (1)

Matt J
Matt J on 27 Mar 2021
Edited: Matt J on 27 Mar 2021
yes, just use find().


Find more on Sparse Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by