Changing a single element in sparse matrices
9 ビュー (過去 30 日間)
古いコメントを表示
I am not very familiar with Matlab and struggling with handling large matrices.
The problem involves about 600000 points and their interactions with each other. I tried to model this with 600000 by 600000 matrix where each element is either 1 or 0, in which 1 represents that the row's point has an interaction with the column's point.
I created the initial matrix with M = speye(600000). Then I tried to run for-loop for each row, converting some chosen elements in that row into 1. To do so, I used the usual M(r,c) = 1 command. Matlab warns me that such indexing expression would be slow, and it indeed is.
Is there a way to modify sparse matrix more efficiently? More broadly, what are the strategies for dealing with such large but simple (in that elements are binary) matrices?
Any sort of advice would be much appreciated.
0 件のコメント
回答 (1 件)
Sarah Wait Zaranek
2011 年 11 月 21 日
In general, it is useful to define the values and locations of the non-zero entries of your sparse matrices - and then only create it once.
There is a useful section in the MATLAB documentation about dealing with sparse matrices here: http://www.mathworks.com/help/releases/R2011b/techdoc/math/f6-32006.html
In particular, look at the sections about accessing and creating sparse matrices for examples.
Also there is a useful blog on Loren's Art of MATLAB here: http://blogs.mathworks.com/loren/2007/03/01/creating-sparse-finite-element-matrices-in-matlab/
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!