Sparse matrix operations cause extra non-zero values (very small)
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Aritra
2023-1-31
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!