public static RealMatrix readMatrix ( Reader reader ) throws IOException { // Initialize the return value: List < double [ ] > retval = new ArrayList <> ( ) ; // Parse and get the iterarable: Iterable < CSVRecord > records = CSVFormat . EXCEL . parse ( reader ) ; // Iterate over the records and populate return value: for ( CSVRecord record : records ) { double [ ] row = new double [ record . size ( ) ] ; for ( int i = 0 ; i < record . size ( ) ; i ++ ) { row [ i ] = Double . parseDouble ( record . get ( i ) ) ; } retval . add ( row ) ; } // Convert the list to an array: double [ ] [ ] retvalArray = new double [ retval . size ( ) ] [ ] ; retval . toArray ( retvalArray ) ; // Done, return the array: return MatrixUtils . createRealMatrix ( retvalArray ) ; }
Reads a matrix of double values from the reader provided .