PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_sort_intmat_rank_rows (m01df)
Purpose
nag_sort_intmat_rank_rows (m01df) ranks the rows of a matrix of integer numbers in ascending or descending order.
Syntax
Note: the interface to this routine has changed since earlier releases of the toolbox:
At Mark 22: |
m2 was made optional |
Description
nag_sort_intmat_rank_rows (m01df) ranks rows
m1 to
m2 of a matrix, using the data in columns
n1 to
n2 of those rows. The ordering is determined by first ranking the data in column
n1, then ranking any tied rows according to the data in column
, and so on up to column
n2.
nag_sort_intmat_rank_rows (m01df) 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 rows preserve their ordering in the input data.
References
Knuth D E (1973) The Art of Computer Programming (Volume 3) (2nd Edition) Addison–Wesley
Parameters
Compulsory Input Parameters
- 1:
– int64int32nag_int array
-
ldm, the first dimension of the array, must satisfy the constraint
.
Columns
n1 to
n2 of rows
m1 to
m2 of
im must contain integer data to be ranked.
- 2:
– int64int32nag_int scalar
-
The index of the first row of
im to be ranked.
Constraint:
.
- 3:
– int64int32nag_int scalar
-
The index of the first column of
im to be used.
Constraint:
.
- 4:
– string (length ≥ 1)
-
If
, the rows will be ranked in ascending (i.e., nondecreasing) order.
If , into descending order.
Constraint:
or .
Optional Input Parameters
- 1:
– int64int32nag_int scalar
-
Default:
the first dimension of the array
im.
The index of the last row of
im to be ranked.
Constraint:
.
- 2:
– int64int32nag_int scalar
-
Default:
the second dimension of the array
im.
The index of the last column of
im to be used.
Constraint:
.
Output Parameters
- 1:
– int64int32nag_int array
-
Elements
m1 to
m2 of
irank contain the ranks of the corresponding rows of
im. Note that the ranks are in the range
m1 to
m2: thus, if the
th row of
im is the first in the rank order,
is set to
m1.
- 2:
– int64int32nag_int scalar
unless the function detects an error (see
Error Indicators and Warnings).
Error Indicators and Warnings
Errors or warnings detected by the function:
-
-
On entry, | , |
or | , |
or | , |
or | , |
or | , |
or | , |
or | . |
-
-
On entry, | order is not 'A' or 'D'. |
-
An unexpected error has been triggered by this routine. Please
contact
NAG.
-
Your licence key may have expired or may not have been installed correctly.
-
Dynamic memory allocation failed.
Accuracy
Not applicable.
Further Comments
The average time taken by the function is approximately proportional to , where .
Example
This example reads a matrix of integers and ranks the rows in descending order.
Open in the MATLAB editor:
m01df_example
function m01df_example
fprintf('m01df example results\n\n');
im = [int64(6),5,4;
5,2,1;
2,4,9;
4,9,6;
4,9,5;
4,1,2;
3,4,1;
2,4,6;
1,6,4;
9,3,2;
6,2,5;
4,9,6];
m1 = int64(1);
n1 = int64(1);
order = 'Descending';
[irank, ifail] = m01df( ...
im, m1, n1, order);
fprintf(' Data Ranks\n\n');
for i = 1:size(im,1)
fprintf('%5d',im(i,:));
fprintf(' %7d\n',irank(i));
end
m01df example results
Data Ranks
6 5 4 2
5 2 1 4
2 4 9 10
4 9 6 5
4 9 5 7
4 1 2 8
3 4 1 9
2 4 6 11
1 6 4 12
9 3 2 1
6 2 5 3
4 9 6 6
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015