How to print .txt from the matrix containing numbers and characters?

2 次查看(过去 30 天)
I want to print the following data into a .txt file.
1 0 R 1km
2 0 R 1km
3 0 R 1km
......
.....
99 0 R 1km
100 0 R 1km
How can I use fprintf to save this data?

采纳的回答

Ameer Hamza
Ameer Hamza 2020-10-12
Something like this
tt = table((1:100).', zeros(100,1), repmat('R', 100, 1), repmat('1km', 100, 1));
writetable(tt, 'data.txt', 'WriteVariableNames', false, 'Delimiter', '\t')
  4 个评论
Ameer Hamza
Ameer Hamza 2020-10-12
Try this
tt = table((1:100).', zeros(100,1), repmat('R', 100, 1), repmat('1km', 100, 1));
C = table2cell(tt).';
f = fopen('test.txt', 'w');
fprintf(f, '%f\t%f\t%s\t%s\n', C{:});
fclose(f);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by