MATLAB: Write matrices in notepad

dlmwriteexporting notepadexporting to excelnotepadwriting notepad

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

Best Answer

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');