nag_sort_realvec_rank (m01da) uses a variant of list-merging, as described on pages 165–166 in
Knuth (1973). The function takes advantage of natural ordering in the data, and uses a simple list insertion in a preparatory pass to generate ordered lists of length at least
. The ranking is stable: equal elements preserve their ordering in the input data.
Not applicable.
This example reads a list of double numbers and ranks them in ascending order.
function m01da_example
fprintf('m01da example results\n\n');
rv = [5.3 4.6 7.8 1.7 5.3 9.9 ...
3.2 4.3 7.8 4.5 1.2 7.6];
m1 = int64(1);
order = 'Ascending';
[irank, ifail] = m01da(rv, m1, order);
fprintf(' Data Ranks\n\n');
for i = 1:numel(rv)
fprintf('%7.1f%7d\n',rv(i),irank(i));
end