Multiple text file read i Matlab
2 ビュー (過去 30 日間)
古いコメントを表示
Khan Muhammad Adeel Khan
2020 年 7 月 10 日
コメント済み: Khan Muhammad Adeel Khan
2020 年 7 月 10 日
I want matlab to read multiple text file. The matlab code to read the single text file and specific line is attached. How to read multiple text from the folder?
fid=fopen('E:\ReliabilityAll\alpha\sub1.txt');
StartLine=3;
for k=1:StartLine-1
fgetl(fid); % read and dump
end
Fline=fgetl(fid); % this is the 3rd line
%do stuff
fclose(fid)
0 件のコメント
採用された回答
madhan ravi
2020 年 7 月 10 日
編集済み: madhan ravi
2020 年 7 月 10 日
for l = 1:8
fid=fopen(sprintf('E:\\ReliabilityAll\\alpha\\sub%d.txt',l));
StartLine=3;
for k=1:StartLine-1
fgetl(fid); % read and dump
end
Fline=fgetl(fid); % this is the 3rd line
%do stuff
fclose(fid)
end
8 件のコメント
その他の回答 (1 件)
Robert
2020 年 7 月 10 日
編集済み: Robert
2020 年 7 月 10 日
You might also use a direct loop on the result of using the 'dir' command, if the '*' placeholder is sufficient for your search. Take care to use the transpose operator ' on the result of dir, because you need a row vector of results to for-loop.
sDir = 'C:\Users\Khan\Documents\MATLAB';
for sctFile = dir(fullfile(sDir, 'sub*.txt'))'
fh = fopen(fullfile(sDir, sctFile.name));
% here goes your code
% ...
fclose(fh);
end
Or just dir on the directory, and filter the file names within the loop..
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Low-Level File I/O についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!