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

조회 수: 29 (최근 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 CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by