[b4b313]: / Semantic Features / NotUsed / bestOfArray.m

Download this file

15 lines (10 with data), 348 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
function [ bestOfArray ] = bestOfArray( array, num )
%bestOfArray Returns array of the same size with all but the top num items
%reduced to zero
sorted = sort(array,'descend');
bestOfArray = zeros(size(array,1), size(array,2));
for i = 1:num
keep = (array == sorted(i));
bestOfArray = bestOfArray + keep .* array;
end
end