I have 200 txt files in a directory and I am wondering how can I read and plot some of them. Lets say that the files names are like
1_Mark_slow , 2_Mark_fast , 3_Mark_slow , 4_Mark_fast , etc.
I would like to read all 'slow' files.
Thanks a lot in advance
You can get a listing of the contents of certain directory using dir
, and filter them using the asterisk. For example:
myPath='/home/digna/myfiles/';
files=dir( fullfile( myPath, '*slow') );
This will return a struct array with information about all the files which filename contains the word "slow". The fields of the structure are the following:
name
date
bytes
isdir
datenum
So you can read them by accessing the name
field:
for i=1:length(files)
file=files(i).name;
filepath = fullfile( myPath, file );
%open and read file using filepath
end
Please see Matlab's fullfile
command for cross-platform concatenation of file names.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.