loading from txt file to matrix(2D array)
in
Programming Questions
•
11 months ago
I would like to insert numbers in txt file "Head.txt" and insert it to a A_matrix but failed with error:
ArrayIndexOutOfBoundsException: 313
my Head.txt will be like for eg.
1 2 3
4 5 6
......
311 312 313
means it takes a form of 313 x 3 matrix..
my code will be as below..
ArrayIndexOutOfBoundsException: 313
my Head.txt will be like for eg.
1 2 3
4 5 6
......
311 312 313
means it takes a form of 313 x 3 matrix..
my code will be as below..
- BufferedReader reader;
- String line;
- int rows=0;
- double[][] A_matrix = new double[313][3];
-
- void setup() {
- // Open the file from the createWriter() example
- reader = createReader("Head.txt");
- }
-
- void draw() {
- try {
- line = reader.readLine();
- } catch (IOException e) {
- e.printStackTrace();
- line = null;
- }
- while(line != null){
- String[] nums = split(line, ' ');
- for(int j=0; j<3; j++){
- A_matrix[rows][j] = Double.parseDouble(nums[j]);
- }
- rows++;
- }
- }
I know that this is not a good program but I couldnt think of any better..Please help me..
I'll send through email or upload on some hosting webpage if anyone need the file Head.txt
I'll send through email or upload on some hosting webpage if anyone need the file Head.txt
1