matlab: Sparse Function for any matrix
古いコメントを表示
I am trying to write a sparse function code for any matrix size. For example if i have a matrix:
A = [ 0 0 0 5
0 2 0 0
1 3 0 0
0 0 4 0];
a=size(A);
b=size(A);
c=0;
position=0;
for i=1:a for j=1:b if A(i,j) ~=0
c=c+1;
position=position+1;
S(c,:)=[position,i,j,A(i,j)];
end
end
end
S
S --> is the storage matrix for all the non zero elements for A matrix. In addition to this information(Index,Row Number, Column Number, Value) how do I include two more columns in the matrix which shows the next element in row & the next element in column.
6 件のコメント
James Tursa
2013 年 10 月 24 日
Can you provide the expected result for the sample matrix you have shown? What do you want stored if there is no next non-zero element in the row or column?
Antony
2013 年 10 月 24 日
Antony
2013 年 10 月 24 日
Cedric
2013 年 10 月 24 日
Why don't you create just a display function which fits your needs, but still use MATLAB sparse matrices for computing?
James Tursa
2013 年 10 月 25 日
@Antony: So you want a linked list that goes by rows, and a separate linked list that goes by columns? And both linked lists have wraparound to next row (or column) and even back to the beginning? Is that what you want?
Antony
2013 年 10 月 25 日
回答 (1 件)
カテゴリ
ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!