I have a function, ranker
, that takes a vector and assigns numerical ranks to it in ascending order. For example,
ranker([5 1 3 600]) = [3 1 2 4]
or
ranker([42 300 42 42 1 42] = [3.5 6 3.5 3.5 1 3.5]
.
I am using a matrix, variable_data
and I want to apply the ranker function to each row for all rows in variable data
. This is my current solution, but I feel there is a way to vectorize it and have it as equally fast :p
variable_ranks = nan(size(variable_data));
for i=1:1:numel(nmac_ids)
variable_ranks(i,:) = ranker(abs(variable_data(i,:)));
end