Info

This question is closed. Reopen it to edit or answer.

how to determine n lowest value of an array and display it on a table.

1 view (last 30 days)
this codes below doing one to many comparation between an iris image template on axes1 and a folder filled with iris image templates. a hammingdist.m used to count the value. the output so far is a template from the folder that has the lowest value from the comparations. my question is how to also determine and display the lowest 10 values from the comparation into a table along with their filenames? here is the codes so far:
TestImage=getappdata(handles.axes1, 'templateok');
gettraining=get(handles.txtlocation, 'String');
datapath = (gettraining);
templatefiles = dir(fullfile(datapath, '*.bmp'));
hammingdistances = zeros(size(templatefiles));
for fileidx = 1:numel(templatefiles)
templateimage = imread(fullfile(datapath, templatefiles(fileidx).name));
hammingdistances(fileidx) = hammingdist(TestImage, templateimage);
end
%finding the lowest value in the array
[minhammingdist,idx]=min(hammingdistances);
axes(handles.axes2);
imshow(imread(fullfile(datapath, templatefiles(idx).name)));

Answers (1)

Image Analyst
Image Analyst on 21 Oct 2017
Sort them then take the lowest 10
%templatefiles = dir('*.m')
%hammingdist = randi(1000, length(templatefiles), 1)
% Get all filenames into one cell array
allFileNames = {templatefiles.name}';
[sortedDistances, sortOrder] = sort(hammingdist, 'ascend');
% Sort names the same way
sortedNames = allFileNames(sortOrder);
% Get the lowest 10
lowest10Distances = sortedDistances(1:10)
lowestFileNames = sortedNames(1:10)
% Make cell array for table
for row = 1 : length(lowest10Distances)
ca{row, 1} = lowestFileNames{row};
ca{row, 2} = lowest10Distances(row);
end
celldisp(ca) % Display in command window
% Put into table
handles.uitable1.data = ca;

Community Treasure Hunt

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

Start Hunting!