Replace elements of sparse matrix from a full matrix.

조회 수: 9 (최근 30일)
KSSV
KSSV 2016년 3월 4일
댓글: Walter Roberson 2016년 3월 5일
Dear Experts
I have a huge matrix, M with zeros. I am converting M into sparse using sparse(M). After, I want to replace few positions (idx) of M from other matrix, N. I am using the following: M(idx) = N(idx). But, this is very very slow. Also MATLAB warns: This sparse indexing expression is slow. How I can do the above task?
Thanks in advance.
  댓글 수: 2
Stephen23
Stephen23 2016년 3월 4일
What size is M?
KSSV
KSSV 2016년 3월 4일
[19647672 60] is the size at present am dealing with. It may be more in future.

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

답변 (1개)

Jos (10584)
Jos (10584) 2016년 3월 4일
What don't you replace the elements before converting it?
  댓글 수: 8
KSSV
KSSV 2016년 3월 5일
Actually my original matrix has zeros and I want to fill these zeros with numbers later...
Walter Roberson
Walter Roberson 2016년 3월 5일
Then spalloc() would be appropriate. If you create a matrix without using it or equivalent then you end up doing a lot of sparse reallocations as you add in new values.

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

카테고리

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