[英]Loop through .txt files in a folder and search for certain characters in the file in MATLAB
如何.dbl and
文件夹中的.dbl and
.txt
文件,查找具有特定编号和条件(例如,“启用激光”)的.txt
文件,然后对关联的.dbl
文件进行处理(如果名称相似)?
我实际上没有太多资源,而且似乎无法使用getfield(files, 'name')
访问要查找的文件名getfield(files, 'name')
因此我真的很困惑。 到目前为止,这是我的问题,以便为我的问题提供更多的结构。
% specify folder with the load function to manipulate .dbl files
folder = 'some folder';
% specify folder that has the data
folder2 = 'some other folder';
cd(folder);
addpath(folder2);
% specify parameters implemented in data collection program
start_delay = 0; % in ps
step_size = 20; % in ps
n_steps = 30;
% loop through folders
files = dir(folder2);
for i = 1:size(files,1)
if i == '*.txt
% find string 'ON'
% find a number in .txt file
% for .txt files with string 'ON', look for .txt files for delay =0, then 20, then 40, etc.
% find associated .dbl file
% manipulate .dbl file
end
end
您要查找的内容是dir
和strfind
的*.xxx
strfind
,请看以下示例:
txtList=dir('*.txt');
sblList=dir('*.dbl');
for ii=1:length(txtList)
fid=fopen(txtList(ii).name);
C= textscan(fid,'%s'); %depends on your formating
C=C{1}{1}; %supposing you .txt is really just one string
fclose(fid);
if (sum(strfind(C,'ON'))) %for .txt files with string 'ON'...
Equals0=strfind(C,'0'); % ... look for =0,...
Equals20=strfind(C,'20'); %then =20
%... etc
end
%you get the idea...
%do whatever you want with dblList
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.