code_junkie

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

Nov 11th, 2011
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. [i,j,val] = find(data)
  2. data_dump = [i,j,val]
  3.  
  4. data = spconvert( data_dump )
  5.  
  6. save -ascii data.txt data_dump
  7.  
  8. fid = fopen('data.txt','w')
  9. fprintf( fid,'%d %d %fn', data_dump )
  10. fclose(fid)
  11.  
  12. pw=java.io.PrintWriter(java.io.FileWriter('c:\retail.txt'));
  13. line=num2str(0:size(data,2)-1);
  14. pw.println(line);
  15. for index=1:length(data)
  16. disp(index);
  17. line=num2str(full(data(index,:)));
  18. pw.println(line);
  19. end
  20. pw.flush();
  21. pw.close();
  22.  
  23. idcs = find(data);
  24. vals = data(idcs);
  25. ...save the index vector and value vector in whatever format you want...
Add Comment
Please, Sign In to add comment