필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
M.R. Ebrahimi
M.R. Ebrahimi 2020년 10월 12일
댓글: M.R. Ebrahimi 2020년 10월 12일
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