PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_sort_realmat_rank_columns (m01dj)
Purpose
nag_sort_realmat_rank_columns (m01dj) ranks the columns of a matrix of double 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_realmat_rank_columns (m01dj) 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_realmat_rank_columns (m01dj) 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.
References
Knuth D E (1973) The Art of Computer Programming (Volume 3) (2nd Edition) Addison–Wesley
Parameters
Compulsory Input Parameters
- 1:
– double array
-
ldm, the first dimension of the array, must satisfy the constraint
.
Rows
m1 to
m2 of columns
n1 to
n2 of
rm must contain double data to be ranked.
- 2:
– int64int32nag_int scalar
-
The index of the first row of
rm to be used.
Constraint:
.
- 3:
– int64int32nag_int scalar
-
The index of the first column of
rm to be ranked.
Constraint:
.
- 4:
– string (length ≥ 1)
-
If
, the columns 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
rm.
The index of the last row of
rm to be used.
Constraint:
.
- 2:
– int64int32nag_int scalar
-
Default:
the second dimension of the array
rm.
The index of the last column of
rm to be ranked.
Constraint:
.
Output Parameters
- 1:
– int64int32nag_int array
-
Elements
n1 to
n2 of
irank contain the ranks of the corresponding columns of
rm. Note that the ranks are in the range
n1 to
n2: thus, if the
th column of
rm is the first in the rank order,
is set to
n1.
- 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 double numbers and ranks the columns in ascending order.
Open in the MATLAB editor:
m01dj_example
function m01dj_example
fprintf('m01dj example results\n\n');
rm = [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 = 'Ascending';
[irank, ifail] = m01dj( ...
rm, m1, n1, order);
fprintf('Data\n');
for i = 1:size(rm,1)
fprintf('%7.1f',rm(i,:));
fprintf('\n');
end
fprintf('\nRanks\n');
fprintf('%7d',irank);
fprintf('\n');
m01dj example results
Data
5.0 4.0 3.0 2.0 2.0 1.0 9.0 4.0 4.0 2.0 2.0 1.0
3.0 8.0 2.0 5.0 5.0 6.0 9.0 8.0 9.0 5.0 4.0 1.0
9.0 1.0 6.0 1.0 2.0 4.0 8.0 1.0 2.0 2.0 6.0 2.0
Ranks
11 8 7 4 5 2 12 9 10 6 3 1
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015