hide long namesshow long names
hide short namesshow short names
Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

NAG Toolbox: nag_sort_charvec_rank_rearrange (m01ec)

Purpose

nag_sort_charvec_rank_rearrange (m01ec) rearranges a vector of character data into the order specified by a vector of ranks.

Syntax

[ch, irank, ifail] = m01ec(ch, m1, irank, 'm2', m2)
[ch, irank, ifail] = nag_sort_charvec_rank_rearrange(ch, m1, irank, 'm2', m2)

Description

nag_sort_charvec_rank_rearrange (m01ec) 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_charvec_rank_rearrange (m01ec) can be called to rearrange a vector of character data 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_charvec_rank_rearrange (m01ec) is called.

References

None.

Parameters

Compulsory Input Parameters

1:     ch(m2) – cell array of strings
m2, the dimension of the array, must satisfy the constraint 0 < m1m20<m1m2.
Elements m1 to m2 of ch must contain character data to be rearranged.
Constraint: the length of each element of ch must not exceed 255255.
2:     m1 – int64int32nag_int scalar
The range of the ranks supplied in irank and the elements of ch to be rearranged.
Constraint: 0 < m1m20<m1m2.
3:     irank(m2) – int64int32nag_int array
m2, the dimension of the array, must satisfy the constraint 0 < m1m20<m1m2.
Elements m1 to m2 of irank must contain a permutation of the integers m1 to m2, which are interpreted as a vector of ranks.

Optional Input Parameters

1:     m2 – int64int32nag_int scalar
Default: The dimension of the arrays irank, ch. (An error is raised if these dimensions are not equal.)
The range of the ranks supplied in irank and the elements of ch to be rearranged.
Constraint: 0 < m1m20<m1m2.

Input Parameters Omitted from the MATLAB Interface

None.

Output Parameters

1:     ch(m2) – cell array of strings
These values are rearranged into rank order. For example, if irank(i) = m1iranki=m1, then the initial value of ch(i)chi is moved to ch(m1)chm1.
2:     irank(m2) – int64int32nag_int array
Used as internal workspace prior to being restored and hence is unchanged.
3:     ifail – int64int32nag_int scalar
ifail = 0ifail=0 unless the function detects an error (see [Error Indicators and Warnings]).

Error Indicators and Warnings

Errors or warnings detected by the function:
  ifail = 1ifail=1
On entry,m2 < 1m2<1,
orm1 < 1m1<1,
orm1 > m2m1>m2.
  ifail = 2ifail=2
On entry,the length of each element of ch exceeds 255255.
  ifail = 3ifail=3
Elements m1 to m2 of irank contain a value outside the range m1 to m2.
  ifail = 4ifail=4
Elements m1 to m2 of irank contain a repeated value.
If ifail = 3ifail=3 or 44, elements m1 to m2 of irank do not contain a permutation of the integers m1 to m2. On exit, the contents of ch may be corrupted. To check the validity of irank without the risk of corrupting ch, use nag_sort_permute_check (m01zb).

Accuracy

Not applicable.

Further Comments

The average time taken by the function is approximately proportional to nn, where n = m2m1 + 1n=m2-m1+1.

Example

function nag_sort_charvec_rank_rearrange_example
ch = {'A02AAF'; 'A02ABF'; 'A02ACF'; 'C02ADF'; 'C02AEF'; 'C05ADF'; 'C05AGF'; 'C05AJF'; 'C05AVF'; 'C05AXF'; 'C05AZF'};
m1 = int64(1);
irank = [int64(6);5;4;10;3;2;7;11;8;9;1];
[chOut, irankOut, ifail] = nag_sort_charvec_rank_rearrange(ch, m1, irank)
 

chOut = 

    'C05AZF'
    'C05ADF'
    'C02AEF'
    'A02ACF'
    'A02ABF'
    'A02AAF'
    'C05AGF'
    'C05AVF'
    'C05AXF'
    'C02ADF'
    'C05AJF'


irankOut =

                    6
                    5
                    4
                   10
                    3
                    2
                    7
                   11
                    8
                    9
                    1


ifail =

                    0


function m01ec_example
ch = {'A02AAF'; 'A02ABF'; 'A02ACF'; 'C02ADF'; 'C02AEF'; 'C05ADF'; 'C05AGF'; ...
      'C05AJF'; 'C05AVF'; 'C05AXF'; 'C05AZF'};
m1 = int64(1);
irank = [int64(6);5;4;10;3;2;7;11;8;9;1];
[chOut, irankOut, ifail] = m01ec(ch, m1, irank)
 

chOut = 

    'C05AZF'
    'C05ADF'
    'C02AEF'
    'A02ACF'
    'A02ABF'
    'A02AAF'
    'C05AGF'
    'C05AVF'
    'C05AXF'
    'C02ADF'
    'C05AJF'


irankOut =

                    6
                    5
                    4
                   10
                    3
                    2
                    7
                   11
                    8
                    9
                    1


ifail =

                    0



PDF version (NAG web site, 64-bit version, 64-bit version)
Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2013