how to read data from multiple files and save in single file
이전 댓글 표시
i have 5000 text files each file having(1*50). i need to read those all files from top to bottom order and want to save them in single text file.which should contain all data from those 5000 files(5000*50).
채택된 답변
추가 답변 (3개)
David Sanchez
2013년 8월 7일
my_files = dir('*.txt');
N_files = numel( my_files );
A = zeros( numel(my_files),50 ); % initialize matrix to hold data
for k = 1:N_files
file2read = my_files(k).name;
fid = fopen(file2read);
A(k,:) = fscanf(fid, '%g', [1 inf]); % data from file
fclose(fid);
end
% write data to new file
fid = fopen('new_file.txt', 'w');
fprintf(fid, '%g %g\n', A);
fclose(fid);
댓글 수: 1
Jan
2013년 8월 7일
The conversion from text to numbers and back again requires a lot of time.
I am trying to do the same as sandy wants to. I am trying to read excel files from two different folders and output it to an excel file present in third folder. Can anyone suggest how can it be done?
P.S : I am reading only a column of data from the two files and not the entire file
hemant vyas
2018년 6월 23일
0 개 추천
sir can we read and write in a video file simultaneously if I am recording video by webcam a saving it in .m file than in the same code i want to process it in matlab2013a
카테고리
도움말 센터 및 File Exchange에서 Text Data Preparation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!