필터 지우기
필터 지우기

Write column in .txt file

조회 수: 11 (최근 30일)
Marisabel Gonzalez
Marisabel Gonzalez 2019년 4월 5일
댓글: Star Strider 2019년 4월 5일
Hi, I would like to know how can I write a column into a .txt file.
Let's say that the output is
A = [0.045; 0.011; 0.003; 0.005]*1.0e-03
I would also like to know how instead I can add the output to an already existing text file as a column, the last column in this case.
Summing up:
  • How to write output in new file as a column
  • How to write output in an existing file as the last column

채택된 답변

Star Strider
Star Strider 2019년 4월 5일
편집: Star Strider 2019년 4월 5일
You have several options.
One approach:
fid = fopen('YourFile.txt,'wt');
fprintf(fid,'%.6f\n',A)
fclose(fid);
Experiment to get the result you want.
EDIT —
You edited your Question, so I’m editing my Answer.
To append the column to the end of an existing file using the dlmread (link) function (consider using the readmatrix (link) function if you have R2019a or later), to read the file into a matrix of the same row size as ‘A’, or truncate ‘A’ or append NaN values to ‘A’ as appropriate to make the row sizes equal, then concatenate it to the end of your matrix. Then write it to a new or existing file name.
The concatenation would be:
NewMMatrix = [OldMatrix A];
The easiest way to write this would be to use the dlmwrite (link) function, or if you have R2019a or later, the writematrix (link) function.
  댓글 수: 7
Marisabel Gonzalez
Marisabel Gonzalez 2019년 4월 5일
I still haven't got it to work (feeling close) but your answer has been useful!
Star Strider
Star Strider 2019년 4월 5일
Thank you.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Labels and Annotations에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by