Azzera filtri
Azzera filtri

how to append three text files together in a new text file ?

3 visualizzazioni (ultimi 30 giorni)
i have just started with matlab and want to know how to read text files and append them together in a new file.

Risposta accettata

KSSV
KSSV il 4 Feb 2019
Modificato: KSSV il 4 Feb 2019
% 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);
  2 Commenti
karan goyal
karan goyal il 4 Feb 2019
thank you soo much .IT worked.
you are a saver.
Stephen23
Stephen23 il 4 Feb 2019
If you are going to use wt for writing then file then you will need to use rt to read the file, otherwise on Windows you will end up with extra carriage return characters.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Data Import and Export in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by