Hello
I have several text files which each of them contains thousands of numbers in 2 columns. I want to integrate them all into one file with the same formate, starting from the first row of the first file and ending with the last row of the last file.

답변 (1개)

David Hill
David Hill 2020년 12월 3일

1 개 추천

Just read them in and concatenate.
b=[];
for n=1:numberoffiles
fileName=sprintf('yourfile%d',n);%assuming file names are numbered
a=readmatrix(fileName);
b=[b;a];%concatenate
end

댓글 수: 5

Morteza Tohidi
Morteza Tohidi 2020년 12월 3일
Thanks David,
What if the file names are not numbered ?
Walter Roberson
Walter Roberson 2020년 12월 3일
If they are not numbered, then which order do they need to be read in? For your purposes, is it okay if the data is put together in any "convenient" order, or does the name of the file influence the order it has to be placed in relative to the other files?
Morteza Tohidi
Morteza Tohidi 2020년 12월 3일
편집: Morteza Tohidi 2020년 12월 3일
They are ordered by the file names change like this
XXX2020-2035
XXX2035-2055
XXX2055-2100
So it is not like simple numbers in row.
Rik
Rik 2020년 12월 3일
If you have a way to order them, you can read them in that order. Are you storing the file names in a struct or a cell?

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

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2020년 12월 2일

댓글:

2020년 12월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by