Multiple text file read i Matlab
13 views (last 30 days)
Khan Muhammad Adeel Khan on 10 Jul 2020
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?
fgetl(fid); % read and dump
Fline=fgetl(fid); % this is the 3rd line
More Answers (1)
Robert on 10 Jul 2020
Edited: Robert on 10 Jul 2020
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
Or just dir on the directory, and filter the file names within the loop..