Insert a header in a txt file
    1 Ansicht (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Emilio Pulli
 am 6 Dez. 2021
  
    
    
    
    
    Kommentiert: Emilio Pulli
 am 8 Dez. 2021
            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 Kommentare
Akzeptierte Antwort
  Alagu Sankar Esakkiappan
    
 am 8 Dez. 2021
        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
Weitere Antworten (0)
Siehe auch
Kategorien
				Mehr zu Text Files finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



