fprintf: writing text lists to .txt files

7 次查看(过去 30 天)
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