Note: the interface to this routine has changed since earlier releases of the toolbox:
At Mark 22: |
m2 was made optional |
nag_sort_intmat_rank_columns (m01dk) ranks columns
n1 to
n2 of a matrix, using the data in rows
m1 to
m2 of those columns. The ordering is determined by first ranking the data in row
m1, then ranking any tied columns according to the data in row
, and so on up to row
m2.
nag_sort_intmat_rank_columns (m01dk) 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 columns preserve their ordering in the input data.
Not applicable.
This example reads a matrix of integers and ranks the columns in descending order.
function m01dk_example
fprintf('m01dk example results\n\n');
im = [int64(5),4,3,2,2,1,9,4,4,2,2,1;
3,8,2,5,5,6,9,8,9,5,4,1;
9,1,6,1,2,4,8,1,2,2,6,2];
m1 = int64(1);
n1 = int64(1);
order = 'Descending';
[irank, ifail] = m01dk( ...
im, m1, n1, order);
fprintf('Data\n');
for i = 1:size(im,1)
fprintf('%5d',im(i,:));
fprintf('\n');
end
fprintf('\nRanks\n');
fprintf('%5d',irank);
fprintf('\n');