change entry of sparse matrix

4 ビュー (過去 30 日間)
NA
NA 2019 年 8 月 10 日
コメント済み: Bruno Luong 2019 年 8 月 10 日
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 件のコメント
Bruno Luong
Bruno Luong 2019 年 8 月 10 日
you forgot to assign sparse(A) to a variable

サインインしてコメントする。

採用された回答

Bruno Luong
Bruno Luong 2019 年 8 月 10 日
編集済み: Bruno Luong 2019 年 8 月 10 日
Change it exactly like regular (non-sparse) matrix:
A(sub2ind(size(A), inx, inx)) = out

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSparse Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by