How to add elements to a sparse matrix

Dear community,
I have a sparse matrix S with the dimensions 2028 rows by 14809 columns. I would like to turn S into a full matrix F with the dimensions 2028 rows by 14927 columns. This means that I would like to define a 2028x14927 matrix of zeros first and then fill it with the elements of S in the correct place.
Here is a small example: Below you can see the first 4 elements of the sparse matrix:
(1,1) 1
(1,2) 2
(1,3) 2
(1,6) 8
...
I would like to turn into something like this:
(1,1) 1
(1,2) 2
(1,3) 2
(1,4) 0
(1,5) 0
(1,6) 8
...
Any ideas? Thank you! Paul

 採用された回答

Julie
Julie 2018 年 8 月 21 日
編集済み: Julie 2018 年 8 月 21 日

1 投票

F=full(S)
F=[F,zeros(2028,14927-14809)];

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2018 年 8 月 21 日

1 投票

S(end, 14927) = 0;
S = full(S) ;
Yokesh
Yokesh 2019 年 4 月 9 日

1 投票

%Create a random 10 x 10 sparse matrix
X = sprand(10,10,0.2);
%For adding elements to an existing Sparse matrix
X(2,2) = 0.025;
X(9,1) = 0.5;
for i = [2 3 5]
X(i,i) = 0.00375;
end
All these assignments will just add data to the existing Sparse matrix

カテゴリ

ヘルプ センター および File ExchangeSparse Matrices についてさらに検索

質問済み:

2018 年 8 月 21 日

編集済み:

2019 年 4 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by