Changing a single element in sparse matrices

6 views (last 30 days)
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.

Answers (1)

Sarah Wait Zaranek
Sarah Wait Zaranek on 21 Nov 2011
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.

Categories

Find more on Sparse Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!