write matrices in notepad

5 次查看(过去 30 天)
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

采纳的回答

Wayne King
Wayne King 2013-9-30
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 个评论
tevzia
tevzia 2013-9-30
\n didnt work somehow but coverting to column is a good idea.
Thank you

请先登录,再进行评论。

更多回答(1 个)

Azzi Abdelmalek
Azzi Abdelmalek 2013-9-30
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!

Translated by