MATLAB: How to put a header in a txt file

headerhelpputtext filetxt

I'd like to put a header in my .txt file. I have a file with 744 lines like below. And I wanna put on the first line the header 'hora'.
001
002
003
004
005
006
...
744

Best Answer

Straight-forward solution would be like this:
% Read the file
fid = fopen('yourData.txt','r');
str = textscan(fid,'%s','Delimiter','\n');
fclose(fid);
% Add your header
str2 = [{'hola!'}; str{1}];
% Save as a text file
fid2 = fopen('output.txt','w');
fprintf(fid2,'%s\n', str2{:});
fclose(fid2);