How can I save a very large MATLAB sparse matrix to a text file?

前端 未结 8 714
孤城傲影
孤城傲影 2021-02-01 06:53

I have a 30000x14000 sparse matrix in MATLAB (version 7), which I need to use in another program. Calling save won\'t write this as ASCII (not supported). Calling full()

8条回答
  •  一向
    一向 (楼主)
    2021-02-01 07:39

    Use the find function to get the indices of non-zero elements...

    idcs = find(data);
    vals = data(idcs);
    ...save the index vector and value vector in whatever format you want...
    

    If you want, you can use ind2sub to convert the linear indices to row, column subscripts.

    If you need to recreate a sparse matrix in matlab from subscripts + values, use spconvert.

提交回复
热议问题