Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
M.R. Ebrahimi
M.R. Ebrahimi le 12 Oct 2020
Commenté : M.R. Ebrahimi le 12 Oct 2020
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?

Réponse acceptée

Ameer Hamza
Ameer Hamza le 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 commentaires
Ameer Hamza
Ameer Hamza le 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);
M.R. Ebrahimi
M.R. Ebrahimi le 12 Oct 2020
Thanks alot.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by