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

前端 未结 8 961
孤城傲影
孤城傲影 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:35

    I saved it as text using Java within MATLAB. MATLAB Code:

    
    pw=java.io.PrintWriter(java.io.FileWriter('c:\\retail.txt'));
    line=num2str(0:size(data,2)-1);
    pw.println(line);
    for index=1:length(data)
        disp(index);
        line=num2str(full(data(index,:)));
        pw.println(line);
    end
    pw.flush();
    pw.close();
    

    Here data is an extremely large sparse matrix.

提交回复
热议问题