Help with saving a matrix
Mostra commenti meno recenti
I have a matrix with dimension MxN double. How can I write this matrix in a .dat file by using the function fprintf ? M and N can be arbitrarily big. Thanks
1 Commento
dpb
il 18 Mar 2015
What's the problem with the examples at
doc fprintf
???
Risposta accettata
Più risposte (1)
Hmmm....answering my own question--ok, they are a little skimpy on generalities, aren't they?
fmt=['%.3f ',1,size(X,2)-1) '%.3f\n']; % format for number columns
fprintf(fid,fmt,X.') % and write--NB: the .' to output in row order
open the file with fopen first, of course, to have a valid file handle and close when done.
NB: There are higher-level routines such as dlmwrite that relieve some of the burdens. A particular key of note in the above is the use of repmat to build the format string of the right number of repeated fields since C i/o is so lame-brained/ill-conceived as to have written the descriptors such that can't introduce a repeat count (can you tell I've been thru another extensive thread just within last few days lamenting many of the shortcomings of C format strings vis a vis Fortran FORMAT?)...
I agree after looking that the examples should be more representative of real practice for more than toy ones that illustrate such issues and mention the storage order issues, etc., etc., etc., ...
Categorie
Scopri di più su Variables in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!