Sparse Matrix Assignment becomes very slow in Matlab

前端 未结 2 1512
伪装坚强ぢ
伪装坚强ぢ 2021-01-20 11:17

I am filling a sparse matrix P (230k,290k) with values coming from a text file which I read line by line, here is the (simplified) code

while ...
                    


        
2条回答
  •  不要未来只要你来
    2021-01-20 12:11

    By far the fastest way to generate a sparse matrix wihtin matlab is to load all the values in at once, then generate the sparse matrix in one call to sparse. You have to load the data and arrange it into vectors defining the row and column indices and values for each filled cell. You can then call sparse using the S = sparse(i,j,s,m,n) syntax.

提交回复
热议问题