How to release zero elements in sparse matrix

11 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Azzi Abdelmalek
Azzi Abdelmalek il 7 Feb 2013
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)

Più risposte (2)

Andrei Bobrov
Andrei Bobrov il 7 Feb 2013
  1 Commento
Jimmy
Jimmy il 7 Feb 2013
Hi Andrei,
Sorry I mean I want to really release the memory and that nzmax() reports 75. But thanks for the quick reply.
Jimmy

Accedi per commentare.


Walter Roberson
Walter Roberson il 7 Feb 2013
The examples of sparse show how to dissect and reconstruct a sparse matrix

Categorie

Scopri di più su Sparse Matrices in Help Center e File Exchange

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by