How to use "dir" command to get desired files in a folder?

8 ビュー (過去 30 日間)
Mr. 206
Mr. 206 2018 年 12 月 4 日
コメント済み: Fangjun Jiang 2018 年 12 月 4 日
I can read files inside a folder by using this piece of code..
Flame_speed_folder = '/home/ali/Test_rig';
Allfiles = dir(fullfile(Flame_speed_folder, '*.txt'));
allData = [];
for k = 1:length(Allfiles)
initialFileName = Allfiles(k).name;
fullFileName = fullfile(Flame_speed_folder, initialFileName);
READ=dlmread(fullFileName,'',1,0,"emptyvalue",911911911);
allData(end+1:end+size(READ,1), :) = READ;
end
How ever this will read all txt files in that folder.
I have files like "ign_phi1.0_p20E05_50.txt", "ign_phi1.0_p3.75E05_37.txt", "ign_phi2.0_p3.75E05_47.txt".............. and so one and another types of file like "lfs_p1.01E05_T298_15.txt", "lfs_p1.01E05_T298_16.txt"..... and so on.
How can i read the "ign" and "lfs" files separeately using this "dir" command.

採用された回答

Fangjun Jiang
Fangjun Jiang 2018 年 12 月 4 日
dir('ign*.txt') and dir('ifs*.txt') should be able to separate them.
  5 件のコメント
Image Analyst
Image Analyst 2018 年 12 月 4 日
Use fliplr() and then sort(), then fliplr() again.
Fangjun Jiang
Fangjun Jiang 2018 年 12 月 4 日
a=dir('ign*.txt');
b={a.name};
c=cellfun(@(x) x(end-5:end),b,'uni',false);
[d,index]=sort(c);
e=a(index);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by