fn_order_field_2D

[X_ordered N_uniq_idx N_each_idx idx_org idx_new] = fn_order_field_2D(X)

Description

The function fn_order_field_2D takes as input a 2D field of indices, in which the indices might not be well ordered and might be 'skippy' (e.g., 4, 5, 8, 12), and output a well-ordered version of the field, in which the indices are well ordered in ascending manner starting with 1 without any skip.

Output

X_ordered: The well-ordered version of the index field X, in which the indices are well ordered in ascending manner starting with 1 without any skip. Intuitively, X_ordered has the same dimension as X.

N_uniq_idx: Number of unique indices in the field

N_each_idx: Counting the frequency of each index appearing in the field

idx_org: List of unique original indices before ordered

idx_new: List of unique ordered indices

Input

X: A 2D field of indices, in which the indices might not be well ordered and might be 'skippy' (e.g., 4, 5, 8, 12)

Example

X = [2 2 3 2;8 8 9 9;5 6 5 5]

The original field of unordered indices which can also be 'skippy', for instance, in this case the indices are 2, 3, 5, 6, 8 and 9.

X =

2 2 3 2

8 8 9 9

5 6 5 5

[X_ordered N_uniq_idx N_each_idx idx_org idx_new] = fn_order_field_2D(X)

The field of ordered indices without any skip as the indices go from 1, 2, 3, 4, 5 and 6

X_ordered =

1 1 2 1

5 5 6 6

3 4 3 3

Number of unique indices in the field

N_uniq_idx =

6

Counting the frequency of each index appearing in the field

N_each_idx =

3

1

3

1

2

2

List of unique original indices before ordered

idx_org =

2

3

5

6

8

9

List of unique ordered indices

idx_new =

1

2

3

4

5

6