write matrices in notepad

2 views (last 30 days)
tevzia
tevzia on 30 Sep 2013
Answered: Azzi Abdelmalek on 30 Sep 2013
Hi I try to write result as a notepad or an excel file. I am using dlmwrite() however i didnt find out how to write each number in a new line.
I have a matrices with 100 values which are shown on the command window like this.
Columns 1 through 21
4 1 1 0 0 0 2 4 1 4 2 4 3 1 2 1 2 1 2 2 3
Columns 22 through 42
4 3 4 1 0 4 2 1 3 3 3 3 0 3 1 0 3 2 1 1 2
I used :
dlmwrite('myfile.txt', M, 'delimiter', ' ', 'newline', 'pc')
and the notepad file is :
4 1 1 0 0 0 2 4 1 4 2 4 3 1 2 1 2 1 2 2 3 4 3 4 1 0 4 2 1 3 3 3 3
but i want them like
4
1
1
0
0
0
2
4
1
How can i print my file like this.
Thank you

Accepted Answer

Wayne King
Wayne King on 30 Sep 2013
I think you can do this:
Either create a column vector in MATLAB and then just use save -ascii
For example:
x = randn(1,500);
x = x';
save('test.txt','x','-ascii')
Use '\n' as the delimiter
x = randn(1,500);
dlmwrite('test.txt',x,'delimiter','\n','newline','pc');
  1 Comment
tevzia
tevzia on 30 Sep 2013
\n didnt work somehow but coverting to column is a good idea.
Thank you

Sign in to comment.

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 30 Sep 2013
dlmwrite('myfile.txt', M', 'newline', 'pc')

Community Treasure Hunt

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

Start Hunting!