필터 지우기
필터 지우기

How to merge multiple text files into one file and keep header of one file? Then loop it together

조회 수: 2 (최근 30일)
Hi All,
I have multiple text files with names like ABF99, ABL100.txt, ABL100(2).txt, ABK101.txt, ABK101(2),...... Each file has a header as follows:
ABF99:
Symbol,Date,Time,Price,Volume
ABF0,01/05/2000,09:58:14,19.30,0
.....
ABL100:
Symbol,Date,Time,Price,Volume
ABL0,01/05/2000,10:58:14,19.45,0
.....
ABL100(2):
Symbol,Date,Time,Price,Volume
ABL0,01/05/2000,11:58:14,18.49,0
.....
ABL101:
Symbol,Date,Time,Price,Volume
ABL1,01/05/2000,09:58:14,17.50,0
......
ABL101(2):
Symbol,Date,Time,Price,Volume
ABL1,01/05/2000,11:58:14,20.50,0
..........
I want to merge two files and keep one header if two files have the same beginning name as ABL100 and ABL100(2). Could you help me instruct me the code for this function? Then I need to loop the files together, however, it has one different letter between the name of files (ABF99, ABL100, ABK101). I can use num2str(i) for the number run from 99 to 150, however, I don't know how to deal with ABF, ABL, ABK. Could you know how I can loop it together?
I try with manual code, however, Matlab show that it has some error:
%%loop
for i = 99:1:150
file1 = ['ABF',num2str(i),'.txt'];
memo1 = importdata(file1,',',1);
file2 = ['ABL',num2str(i),'.txt'];
memo2 = importdata(file2,',',1);
file3 = ['ABK',num2str(i),'.txt'];
memo3 = importdata(file3,',',1);
........
% figure;
% plot(memo.data(:,1));
end
Thanks a lot for your help.
  댓글 수: 1
Jan
Jan 2016년 4월 24일
If you mention, that Matlab finds an error, post the error message instead of letting all readers search the error again. Thanks.

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Electrophysiology에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by