How can I save matrix to .txt file?

I have numerical matrix size of 64*60 and I like to save it to .txt file. How can I do it as easy as possible? without repeating %d with fprintf?

 Accepted Answer

Friedrich
Friedrich on 13 Mar 2013
Edited: Friedrich on 13 Mar 2013
Hi,
use dlmwrite
a = rand(64,60);
dlmwrite('filename.txt',a)

5 Comments

Now it's working. Thanks!
a=rand(64,60)
is the matrix?
dlmwrite is not recommended anymore. Use writematrix
a = rand(64,60);
writematrix(a, 'filename.txt')

Sign in to comment.

More Answers (2)

Sudhir Rai
Sudhir Rai on 17 Nov 2020
Use this to get perfect matrix in .txt
X = rand(64,60)
save ('filename.txt', 'X', '-ascii')

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!