필터 지우기
필터 지우기

fprintf: writing text lists to .txt files

조회 수: 8 (최근 30일)
William
William 2011년 10월 28일
I need some help exporting some text lists in cell arrays to .txt functions. I have a list of names in an n x 1 array, called 'assets'. I would like to export it to a .txt file ('assets.txt'). My code currently states:
fid = fopen('assets.txt', 'w');
for row = 1:length(assets)
fprintf(fid, '%s\n', assets(row));
end
fclose(fid)
I get this error message: "Function is not defined for 'cell' inputs." What am I doing wrong?

채택된 답변

Grzegorz Knor
Grzegorz Knor 2011년 10월 28일
You have to change round brackets into curly brackets:
assets = {'first','second','third','fourth'};
fid = fopen('assets.txt', 'w');
for row = 1:length(assets)
fprintf(fid, '%s\n', assets{row});
end
fclose(fid);
  댓글 수: 1
William
William 2011년 12월 7일
It took a while for me to get back to this, but: thanks, that did the trick.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Grzegorz Knor
Grzegorz Knor 2011년 10월 28일
Probably:
fprintf(fid, '%s\n', assets{row});

William
William 2011년 10월 28일
...Ok, let me rephrase. How do I need to phrase my code to write my list to a .txt file?

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by