package com.imsl.test.example.stat; import com.imsl.math.*; import com.imsl.stat.*; /** *

Sorts a matrix using columns as keys.

* *

The rows of a \(10 \times 3\) matrix are sorted in ascending order using Columns \(0\) and \(1\) as the keys. There are two missing values (NaNs) in the keys. The observations containing these values are moved to the end of the sorted array.

* * @see Code * @see Output */ public class SortEx2 { public static void main(String args[]) { int nKeys = 2; double x[][] = { {1.0, 1.0, 1.0}, {2.0, 1.0, 2.0}, {1.0, 1.0, 3.0}, {1.0, 1.0, 4.0}, {2.0, 2.0, 5.0}, {1.0, 2.0, 6.0}, {1.0, 2.0, 7.0}, {1.0, 1.0, 8.0}, {2.0, 2.0, 9.0}, {1.0, 1.0, 9.0} }; int iperm[] = new int[x.length]; x[4][1] = Double.NaN; x[6][0] = Double.NaN; PrintMatrix pm = new PrintMatrix("The Input Array"); PrintMatrixFormat mf = new PrintMatrixFormat(); mf.setNoRowLabels(); mf.setNoColumnLabels(); // Print the array pm.print(mf, x); System.out.println(); try { Sort.ascending(x, nKeys, iperm); } catch (Exception e) { } pm = new PrintMatrix("The Sorted Array - Lowest to Highest"); mf = new PrintMatrixFormat(); mf.setNoRowLabels(); mf.setNoColumnLabels(); // Print the array pm.print(mf, x); pm = new PrintMatrix("The permutation array"); mf = new PrintMatrixFormat(); mf.setNoRowLabels(); mf.setNoColumnLabels(); pm.print(mf, iperm); } }