针对特定属性过滤数组中的字符串 Matlab

Filter Strings in Array for Specific Attributes Matlab

我在 table 中有一列字符串,表示由 dir 函数生成的文件夹中的文件名。

tmpList = struct2table(dir('myFolder'));

该文件夹包含许多不同的文件类型和文件夹。我只想要 excel 个文件,我可以使用以下方法找到这些文件:

filesData = [dir(['myFolder','\*.xlsx']);dir(['myFolder','\*.xls'])];

但是,我该如何展开/替换它,以便我可以过滤 tmpList.name 以仅包含具有以下属性的文件:

例如,对于以下列表,仅标识 1 和 2 以保留:

  1. 'DTE123456.xlsx'
  2. 'Dte01234567.xls'
  3. 'abc12345678.xlsx'
  4. 'DTE12345c34.xls'
  5. 'DTE123456.doc'

您可以使用正则表达式查找符合条件的文件名,然后 cellfuntmpList:

中查找这些文件名的索引
tmpList = struct2table(dir('myFolder')); % your beginning

filteredTmpList = regexpi(tmpList.name(:), '^dte\d{6,8}\.xlsx?$', 'match');
finalList = tmpList(~cellfun('isempty',filteredTmpList), :);