Matlab 在已排序文件的文件夹中查找特定文件
我有一个包含不同文件扩展名的文件夹,例如.txt、.xls 这些文件按以下顺序命名:Matlab 在已排序文件的文件夹中查找特定文件,matlab,Matlab,我有一个包含不同文件扩展名的文件夹,例如.txt、.xls 这些文件按以下顺序命名: 20190228_0_20_20 20190228_50_20_50 我已经整理了所有扩展名为.txt的文件。在这个已排序的文件夹中,我想对一个名为20190218_0_20_20的特定文件进行优化,然后加载它,然后进行一些计算。这是我的密码 非常感谢: %processing the parent folder myfolder ='C:\Users\yannick\Desktop\Windkanal_
- 20190228_0_20_20
- 20190228_50_20_50
%processing the parent folder
myfolder ='C:\Users\yannick\Desktop\Windkanal_Data\Yannick';
if~isdir(myfolder)
Error_message =sprintf('Error,Folder not found :\n %s',myfolder);
end
%Getting list of all files with file pattern .txt
filepattern =fullfile(myfolder,'*.txt');
txtfiles=dir(filepattern);
%sorting out the file with name 20190228_0_20_20 .txt
嗯,我们必须运用一些相当疯狂的猜测来猜测你在这里想做什么,但我会试一试:
% dir only those that match your format
filepattern =fullfile(myfolder,'20190228_0_*_*.txt');
% get all matching files
txtfiles=dir(filepattern);
% let's loop them
for iFile = 1:length(txtfiles)
% extracting the x and y from the file name of the current file
fn_parts = split(f(iFile).name,{'_','.'});
coor_x = str2double(fn_parts{3});
coor_y = str2double(fn_parts{4});
% now you know the coordinates (x,y) that belong to the current file. You can use this to search for a specific coordinate if you like (though it would be easier to do this earlier I guess)
% next step is reading it I guess. I have no idea about your file format. Try dlmread? importdata?
fcontents = importdata(fullfile(f(iFile).folder,f(iFile).name));
% process further...
end
如果您已经知道确切的文件名和路径,为什么还要搜索(dir)呢?为什么不直接加载呢?不确定您的txt文件的格式,但您可以尝试dlmread或importdata。@Florian谢谢,我只是在练习,我很高兴尝试不同的东西。我只想处理完整的折叠文件,而不是单个txt文件。因为对于其他文件,我需要执行一些计算,然后绘制一个图。我的文件格式是20190228_50_20_20,只是x和y坐标的最后两个数字正在更改。。。。谢谢你,我需要你的帮助很好,很高兴听到你这么说。考虑接受答案,如果它解决了你的问题。对于每一个文件,我需要计算5个参数,每个维度15000 0x1,然后保存在一个新的TxTfile中,包含坐标的位置。请告诉我需要帮助这不是一个恰当的问题。你真的需要学会以正确的方式提问。从这里开始阅读: