Insert a header in a txt file

조회 수: 22 (최근 30일)
Emilio Pulli
Emilio Pulli 2021년 12월 6일
댓글: Emilio Pulli 2021년 12월 8일
How can I insert a header in a txt file without deleting the contents and the format of the txt file? I would like simply to insert a header on top of all the columns of data in order to specify the variable of each column.
  댓글 수: 3
Emilio Pulli
Emilio Pulli 2021년 12월 6일
I want to insert a header per each column corresponding to the name of the variable of that specific column
Walter Roberson
Walter Roberson 2021년 12월 6일
writetable instead of writematrix.

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

채택된 답변

Alagu Sankar Esakkiappan
Alagu Sankar Esakkiappan 2021년 12월 8일
Hi Emilio,
I see that you're trying to add new Column headers to the same text file without deleting its original content. This may be achieved using writetable function and its properties.
You may refer to the following code snippet as reference:
inputTable = readtable("dataset_red.txt"); % Reads current file contents as a Table
inputTable.Properties.VariableNames = {'Data 1','Data 2','Data 3','Data 4','Data 5','Data 6'} % Add Text Header for Each Column
writetable(inputTable,"dataset_red.txt","Delimiter", '\t'); % Overwrite same Text file with Tab as Delimiter

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Text Files에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by