Clear Filters
Clear Filters

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

1 view (last 30 days)
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.

Answers (1)

Aritra
Aritra on 31 Jan 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:

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!