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

1 view (last 30 days)
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?

Accepted Answer

Ameer Hamza
Ameer Hamza on 12 Oct 2020
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 Comments
Ameer Hamza
Ameer Hamza on 12 Oct 2020
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);

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!