nag_sort_realvec_rank_rearrange (m01ea) is designed to be used typically in conjunction with the M01D ranking functions. After one of the M01D functions has been called to determine a vector of ranks,
nag_sort_realvec_rank_rearrange (m01ea) can be called to rearrange a vector of real numbers into the rank order. If the vector of ranks has been generated in some other way, then
nag_sort_permute_check (m01zb) should be called to check its validity before
nag_sort_realvec_rank_rearrange (m01ea) is called.
None.
If
or
, elements
m1 to
m2 of
irank do not contain a permutation of the integers
m1 to
m2. On exit, the contents of
rv may be corrupted. To check the validity of
irank without the risk of corrupting
rv, use
nag_sort_permute_check (m01zb).
Not applicable.
This example reads a matrix of real numbers and rearranges its rows so that the elements of the
th column are in ascending order. To do this, the program first calls
nag_sort_realvec_rank (m01da) to rank the elements of the
th column, and then calls
nag_sort_realvec_rank_rearrange (m01ea) to rearrange each column into the order specified by the ranks. The value of
is read from the datafile.
function m01ea_example
fprintf('m01ea example results\n\n');
k = int64(1);
rm = [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);
m2 = int64(size(rm,1));
n = int64(size(rm,2));
order = 'Ascending';
[irank, ifail] = m01da(rm(:,k), m1, order);
for j = 1:n
[rm(:,j), irank, ifail] = m01ea(rm(:,j), m1, irank);
end
fprintf('Matrix sorted on column %2d\n', k);
for i = m1:m2
fprintf('%7.1f',rm(i,:));
fprintf('\n');
end