printf newline not working

4 ビュー (過去 30 日間)
Wyatt Rees
Wyatt Rees 2016 年 4 月 26 日
回答済み: Walter Roberson 2016 年 4 月 26 日
I am trying to write a newline to a .txt file in between each string in a set of strings. The code I currently have is:
fileID = fopen('hex.txt','w');
fprintf(fileID,'%s\r\n',hex_str);
fclose(fileID);
where hex_str is a 1x20 array of strings. I have also tried using \n instead of \r\n but that does not work either. I've also tried using 'wt' instead of 'w' in the permission field of fopen, but that did not help either. I think this may be an issue with using the built in notepad on my machine (Windows 7). I have downloaded notepad++, but how do I get matlab to use this software when writing instead of the builtin notepad?

回答 (2 件)

MHN
MHN 2016 年 4 月 26 日
I could not understand the question. You have 20 words that you would like to put a new line after each of them, is it correct? could you upload your hex.txt and hex_str. Or at least an example of it.

Walter Roberson
Walter Roberson 2016 年 4 月 26 日
fileID = fopen('hex.txt','w');
fprintf(fileID,'%s\r\n',hex_str{:});
fclose(fileID);

カテゴリ

Help Center および File ExchangeProgramming Utilities についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by