MATLAB: How to append three text files together in a new text file

#append#textfiles

i have just started with matlab and want to know how to read text files and append them together in a new file.

Best Answer

% REad file1
fid = fopen(file1,'rt') ; % edited as suggested by Stephen Cobeldick
S1 = textscan(fid,'%s','delimiter','\n') ;
S1 = S1{1} ;
fclose(fid) ;
% Read file2
fid = fopen(file2,'rt') ;
S2 = textscan(fid,'%s','delimiter','\n') ;
S2 = S2{1} ;
fclose(fid) ;
% Append both the files
S12 = [S1 ; S2] ;
% Write to file
fid = fopen('data.txt','wt') ;
fprintf(fid,'%s\n',S12{:});
fclose(fid);