How to release zero elements in sparse matrix

조회 수: 7 (최근 30일)
Jimmy
Jimmy 2013년 2월 7일
Hi,
The Matlab document says sparse matrix does not release elements from memory when they are set to zero. Then how can I release the elements if they are zero?
For example:
>> a=sparse(ones(10,10));
>> nzmax(a)
ans =
100
>> a(1:5,1:5)=0;
>> nzmax(a)
ans =
100
>>
What I want is that nzmax(a) reports 75 since I don't want to waste the memory for 25 zeros. Is there any command I can use?
Thanks in advance!
Edit: Made the description of example clear.

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 2월 7일
Your example is not correct, what you should do is
a=ones(10,10);
nzmax(a)
a(1:5,1:5)=0
a=sparse(a)
nzmax(a)

추가 답변 (2개)

Andrei Bobrov
Andrei Bobrov 2013년 2월 7일
  댓글 수: 1
Jimmy
Jimmy 2013년 2월 7일
Hi Andrei,
Sorry I mean I want to really release the memory and that nzmax() reports 75. But thanks for the quick reply.
Jimmy

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


Walter Roberson
Walter Roberson 2013년 2월 7일
The examples of sparse show how to dissect and reconstruct a sparse matrix

카테고리

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