Accessing order pair from sparse matrix

조회 수: 1 (최근 30일)
Marcus Rosales
Marcus Rosales 2021년 3월 27일
댓글: Marcus Rosales 2021년 3월 27일
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
etc...
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...

채택된 답변

Jan
Jan 2021년 3월 27일
편집: Jan 2021년 3월 27일
Do you want to get the indices of the non-zero elements?
[i,j,s] = find(S);
The is taken from
help sparse
  댓글 수: 1
Marcus Rosales
Marcus Rosales 2021년 3월 27일
Yes! This'll make my code much faster. Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt J
Matt J 2021년 3월 27일
편집: Matt J 2021년 3월 27일
yes, just use find().
[I,J,Vals]=find(S);

카테고리

Help CenterFile Exchange에서 Sparse Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by