Here you can find the source of loadTimeseries(File file, String delimeter, int _amountOfLines)
Parameter | Description |
---|---|
file | a parameter |
delimeter | a parameter |
_amountOfLines | a parameter |
Parameter | Description |
---|---|
FileNotFoundException | an exception |
public static double[][] loadTimeseries(File file, String delimeter, int _amountOfLines) throws FileNotFoundException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { /**//from www . jav a2 s . c o m * Load a 3D (3 axes) time series csv file to a 2D array. * * @param file * @param delimeter * @param _amountOfLines * @return * @throws FileNotFoundException */ public static double[][] loadTimeseries(File file, String delimeter, int _amountOfLines) throws FileNotFoundException { // load values to list Scanner scanner = new Scanner(file); scanner.useDelimiter("\n"); List<Double[]> valuesList = new ArrayList<Double[]>(); while (scanner.hasNext()) { String[] tokens = scanner.next().split(delimeter); Double[] curVal = new Double[3]; // we expect 3 orthogonal axes for (int i = 0; i < curVal.length; i++) { curVal[i] = Double.valueOf(tokens[i]); } valuesList.add(curVal); } scanner.close(); // convert to 2D array if (_amountOfLines == -1) { _amountOfLines = valuesList.size(); } double[][] valuesArray = new double[_amountOfLines][3]; for (int sampleNr = 0; sampleNr < _amountOfLines; sampleNr++) { Double[] curVal = valuesList.get(sampleNr); for (int i = 0; i < curVal.length; i++) { valuesArray[sampleNr][i] = curVal[i]; } } return valuesArray; } }