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.

回答(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