MATLAB Answers

Naime
0

change entry of sparse matrix

Asked by Naime
on 10 Aug 2019
Latest activity Commented on by Bruno Luong
on 10 Aug 2019
I have sparse matrix. I want to change entry [2;3;5] to [0.01;3.4;4.1]
A=[1,0,0,0,0;0,2,0,0,0;0,0,4,0,0;0,0,0,3,0;0,0,0,0,6];
sparse(A);
out=[0.01;3.4;4.1];
inx=[2;3;5];
rssult should be
(1,1) 1
(2,2) 0.01
(3,3) 3.4
(4,4) 3
(5,5) 4.1
I do not know how to change entry of sparse matrix

  1 Comment

Bruno Luong
on 10 Aug 2019
you forgot to assign sparse(A) to a variable

Sign in to comment.

1 Answer

Answer by Bruno Luong
on 10 Aug 2019
Edited by Bruno Luong
on 10 Aug 2019
 Accepted Answer

Change it exactly like regular (non-sparse) matrix:
A(sub2ind(size(A), inx, inx)) = out

  0 Comments

Sign in to comment.