필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
karan goyal
karan goyal 2019년 2월 4일
편집: KSSV 2019년 2월 4일
i have just started with matlab and want to know how to read text files and append them together in a new file.

채택된 답변

KSSV
KSSV 2019년 2월 4일
편집: KSSV 2019년 2월 4일
% 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
karan goyal
karan goyal 2019년 2월 4일
thank you soo much .IT worked.
you are a saver.
Stephen23
Stephen23 2019년 2월 4일
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.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by