# Sparse matrix operations cause extra non-zero values (very small)

4 visualizaciones (últimos 30 días)

Respondida: Aritra el 31 de En. de 2023
I have two big sparse matrix A, B and I want to get
C=A\B
However, many of the elements in C are actually very small (<1e-10), which I think is due to precision. This would lead to a significant increase of the memory to store C.
My question is, what should I do to eliminate those small numbers, before actually storing them? I don't want to make some selections to the elements of C after its creation, which already takes up memories.
##### 0 comentariosMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos

Iniciar sesión para comentar.

### Respuestas (1)

Aritra el 31 de En. de 2023
Hi,
As per my understanding you are trying to convert values under a certain threshold (<1e-10) to 0.
You can make use of logical indexing for the task. Suppose you have a vector A with 5 elements, and you want to convert the values less than 3 to 0. Consider the following example illustrating the idea:
A = [1,2,3,4,5];
t = A(1:end)<3;
A(t) = 0;
For more details on logical indexing, you can refer to the below documentation on MATRIX Indexing in MATLAB:
##### 0 comentariosMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos

Iniciar sesión para comentar.

### Categorías

Más información sobre Sparse Matrices en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by