文件夹中文件的索引

时间:2013-03-11 12:43:20

标签: matlab file-handling

我有一个大约1000张图像的数据库,我正在进行纹理匹配。我已经创建了特征向量,并为一个图像创建特征向量需要几分钟。现在我正在做匹配的部分。因为我不想再次计算测试图像的功能,我想在给定的文件夹中找到它的索引。

示例:用户选择image_XXXXX.jpg。我想要这个文件的“索引”,即它在该文件夹中的位置

有谁能告诉我如何找到用户使用MATLAB选择的文件索引(在文件夹中)?

1 个答案:

答案 0 :(得分:1)

您可以使用strcmp查找此索引:

% get all file names in folder
tmp = dir('*.jpg');

% logical index of the chosen file
logicalIDX = strcmp({tmp.name}, 'image_XXXXX.jpg');

% numerical index of the chosen file
numericIDX = find(logicalIDX); 

% probably more interesting for this particular case: 
% the numerical index of all the files that have to be processed:
numericIDX = find(~logicalIDX); 
相关问题