Effacer les filtres
Effacer les filtres

how to extract corresponding file name from recognized index

4 vues (au cours des 30 derniers jours)
yan abr
yan abr le 12 Déc 2017
Commenté : yan abr le 12 Déc 2017
I have the following code:
distances = pdist2(TE,TR); %testing sample(TE) and training sample(TR)
[Euc_dist_min , Recognized_index] = min(distances,[], 2)
From the above code, i got the min distance and corresponding index. For example i have 3 faces for testing and 6 faces for training:
Euc_dist_min =
23.4417
25.2491
20.4378
Recognized_index =
1
4
5
How can i get the corresponding file names that represent those index.I name them as 0101,0102,0103,0201,0202,0203(.txt).I use
for k=1:length(Recognized_index)
OutputFileName = Recognized_index(k).name
end
but i got an error 'Struct contents reference from a non-struct array object'. My training files obtained as follows:
FolderTrain = 'D:\train';
AllTrainFiles = fullfile(FolderTrain, '*.txt');
TrainFiles = dir(AllTrainFiles);
for i=1:length(TrainFiles)
baseTrainFilename = (TrainFiles(i).name);
TrainFileName = fullfile(FolderTrain, baseTrainFilename);
fid = fopen(TrainFileName);
A{i} = fscanf(fid, '%d %d %d');
fclose(fid);
end
Thank you.

Réponse acceptée

KL
KL le 12 Déc 2017
Your code snippets are quite unclear but if you want to index certain elements from the dir output, that's just like indexing anything else on matlab. For example if you want to extract only 1st, 3rd and 5th filenames from the struct
OutputFileNames = {TrainFiles([1 3 5]).name};
if you want to use Recognized_index there,
OutputFileNames = {TrainFiles(Recognized_index).name};
Is this what you want?
  1 commentaire
yan abr
yan abr le 12 Déc 2017
yes sir..i need the second one. Thank you for your help.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by