Java Reading Matrix from File in Java - Can Someone Help?

  • Thread starter Thread starter russel.arnold
  • Start date Start date
  • Tags Tags
    File Reading
AI Thread Summary
The discussion focuses on reading matrix rows from a file in Java, specifically formatted as (2:1,3), (4:3,1), (2:1,8). The syntax indicates that the numbers are separated by delimiters ":" and ",", which serve to delineate the integers within the matrix. The input represents a 3x3 matrix similar to MATLAB's format. A suggested approach for reading the data involves using BufferedReader to read the entire line as a string and then parsing it character by character to extract the integers. This method is recommended for those who may not have access to simpler parsing techniques.
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
 
Technology news 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.
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
10
Views
2K
Replies
1
Views
3K
Replies
4
Views
1K
Replies
1
Views
2K
Replies
57
Views
5K
Replies
20
Views
3K
Back
Top