필터 지우기
필터 지우기

Problem with sparse matrix - HELP

조회 수: 2 (최근 30일)
rodrigo
rodrigo 2013년 10월 16일
댓글: Cedric 2013년 10월 16일
Hello all,
Supose that H = sparse(i,j,s),
where i,j,s is an arrays of values with index of row, index of columns and the value of each position.
Then, i will get the sparse matrix.
But my question is: how can i get the vectors i,j,s from an sparse matrix, or even from the correspondent full matrix !
Thanks in advance,

채택된 답변

Cedric
Cedric 2013년 10월 16일
편집: Cedric 2013년 10월 16일
[i,j,s] = find( H ) ;
Note that most often, when building a sparse matrix with vectors of indices/values, it is relevant to specify the size of the matrix:
H = sparse(i, j, s, m, n) ;
otherwise you might get a matrix which doesn't have the appropriate dimension for further computations.
  댓글 수: 2
rodrigo
rodrigo 2013년 10월 16일
Thanks Cedric.
By the way, how can i maintain the zeros of my matrix in vector s and the correspondent indexes in vectors i and j ?
Cedric
Cedric 2013년 10월 16일
편집: Cedric 2013년 10월 16일
You're welcome.
What is the purpose of maintaining zeros? This is precisely what we are trying to avoid when using sparse matrices. Could you describe a bit in which context you need these zeros? If you want to have a vector with all elements of the matrix, just use linear indexing or reshape, e.g.
>> H = randi( 10, 2, 3 )
H =
9 2 7
10 10 1
>> s = H(:)
s =
9
10
2
10
7
1
Note that if s contains all values, you don't need indices. The only thing that you need is to know the initial size (or even just the number of rows or columns and not both) of the matrix (and understand that MATLAB stores numeric arrays column first); using the size and s, you can reshape s into the original matrix:
>> H2 = reshape( H, 2, [] )
H2 =
9 2 7
10 10 1

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

추가 답변 (0개)

카테고리

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