writing maxtrix into a txt file
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I am trying to write a maxtrix into a txt file which contains other information, so i am wondering how i would go about this? could i use dlmwrite, will this write everything in the same file as my other information? Thanks.
p.s. right now i am writing every number in one by one with a nested loop, takes a long time to do since i have a 24000X103 matrix, and also takes forever to open.
0 Commenti
Risposta accettata
Walter Roberson
il 17 Gen 2012
dlmwrite() cannot handle a mix of text and numbers. It can handle numbers alone, and it can handle text alone (when backed in to a corner.)
Are you just trying to append a matrix to an existing file? If so then:
thisfmt = [repmat('%g ', 1, size(YourMatrix,2)-1),, '%g\n'];
fid = fopen('YourExistingFile.txt', 'at');
printf(fid, thisfmt, YourMatrix .'); %transpose is critical!
fclose(fid)
Adjust the %g to whatever is appropriate.
2 Commenti
Walter Roberson
il 17 Gen 2012
The above code will write 24000 rows each containing 103 columns -- "row major order".
Did you want to write by columns across rather than by rows?
thisfmt = [repmat('%g ', 1, size(YourMatrix,1)-1),, '%g\n'];
fid = fopen('YourExistingFile.txt', 'at');
printf(fid, thisfmt, YourMatrix); %NO transpose!
fclose(fid)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Cell Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!