2

I am trying to write the array values to CSV file in MATLAB using the following code

m=[3 12 15 ; 4 23 565];
dlmwrite('C:\Users\amar-admin\Desktop\abc.txt', m)
type C:\Users\amar-admin\Desktop\abc.txt

the output printed in the console is

3,12,15
4,23,565

but the output in File is

3,12,154,23,565
Amarjit Dhillon
  • 2,718
  • 3
  • 23
  • 62

2 Answers2

2

You may want to set the 'newline' option to 'pc':

dlmwrite('C:\Users\amar-admin\Desktop\abc.txt', m, 'newline', 'pc');

This will ensure that the file is created with a carriage return (\r) and a line feed (\n) at the end of each line, instead of potentially just a line feed, which could affect how it is displayed in certain text viewers. See this post for more information about the differences between \n and \r.

gnovice
  • 125,304
  • 15
  • 256
  • 359
1

the issue was solved using .rtf extension

dlmwrite('C:\Users\amar-admin\Desktop\abc.rtf', m)

But, I still wonder if same is possible to .txt file

Amarjit Dhillon
  • 2,718
  • 3
  • 23
  • 62