How to print each cell in cell array (of strings) on new row?

22 ビュー (過去 30 日間)
Benjamin Schuessler
Benjamin Schuessler 2018 年 3 月 26 日
コメント済み: Jan 2018 年 3 月 26 日
Hey all,
I'm having trouble trying to print a cell array, where each cell is on a new line.
For example, lets say we have:
str = {"a" "b" "c"}
and then print the output, where each cell is on a new line. I then wish to write this output to a text file. I just need a little push in the right direction.
Thank you!

採用された回答

Birdman
Birdman 2018 年 3 月 26 日
print the output, where each cell is on a new line
>> str{:}
ans =
"a"
ans =
"b"
ans =
"c"
write this output to a text file
str = {"a" "b" "c"}
fileID = fopen('str.txt','w');
fprintf(fileID,'%s\n%s\n%s',str{:});
fclose(fileID)
  2 件のコメント
Benjamin Schuessler
Benjamin Schuessler 2018 年 3 月 26 日
Ugh, super simple.. THANKS!
Jan
Jan 2018 年 3 月 26 日
Or simpler:
fprintf(fileID, '%s\n', str{:});

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT-Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by