Reading Matrix from File in Java - Can Someone Help?

  • Context: Java 
  • Thread starter Thread starter russel.arnold
  • Start date Start date
  • Tags Tags
    File Reading
russel.arnold
Messages
38
Reaction score
0
hi want to read the rows of a matrix from a file which are written in the following way :

(2:1,3), (4:3,1), (2:1,8)

i am working in java, i am not able to figure out how to do this using bufferedreader :(

can someone help?

Thanks
 
on Phys.org
What is the exact meaning of the syntax (2:1,3) etc?
 
(2:1,3) represents 2,1 and 3 elements of a row. ":" and "," are just the delimiters, my task is to separate the integers from these delimiters
 
Ok got it. The row element delimiter can be either "," or ':". They are equivalent and they have no other special meaning.

Just to confirm then, in your example you're inputting a 3x3 matrix like the MATLAB equiv of [2,3,1; 4,3,1; 2,1,8]

Code:
2 3 1
4 3 1
2 1 8

I'm no expert on java, but if you can't find any easier method then you could always use "bufferedreader.readln()" to read the entire line as a string and then just go through it character by character. Parsing from first principles as it were.
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 3 ·
Replies
3
Views
7K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 4 ·
Replies
4
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 57 ·
2
Replies
57
Views
7K
Replies
1
Views
2K
  • · Replies 20 ·
Replies
20
Views
5K