How to get the compressed row sparse CRS in a matrix ?

4 Ansichten (letzte 30 Tage)
kalana agampodi
kalana agampodi am 11 Okt. 2021
Bearbeitet: kalana agampodi am 11 Okt. 2021
I want to get the compressed row sparse (CRS) of the following matrix.
A=[ 1 0 -2 0 0;...
2 8 0 1 0;...
0 0 3 0 -2;...
0 -3 2 0 0;...
1 2 0 0 -4]
So far I have the folliwing code but how ever I do not know to get the row pointer. Hoow do I get the row pointer for the above matrix ?
So far i have...
n=length(A);
c=1;
for i=1:n
for j=1:n
if A(i,j) ~= 0;
row(c,1)=i;
col(c,1)=j;
val(c,1)=A(i,j);
index(c,1)= c;
data = {index, val};
c=c+1;
end
end
end

Antworten (0)

Kategorien

Mehr zu Sparse Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by