I'm trying to work on the UJMP library. I created a matrix and I'd like to export it in a txt file and then to import it again as a basic Matrix. I tried the following code but it doesn't work:
Matrix m = MatrixFactory.dense(ValueType.INT, new long[]{(long)100,(long)100});
for(int i = 0; i< 100; i++){
for(int j = 0; j< 100;j++){
m.setAsInt((int) (Math.random() *3),new long[]{i,j});
}
}
try {
m.exportToFile(FileFormat.TXT,"test.txt",null); //this works. My file contains the matrix
} catch (MatrixException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Matrix n = null;
try {
n =ImportMatrix.fromFile(FileFormat.TXT,new File("test.txt"),null); //this doesn't work. The matrix has a size of 1*1 and contains the content of the previous matrix as a single string.
} catch (MatrixException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(n.getSize()[0]+" "+n.getSize()[1]); // I get 1 1;
So what should I do to get my original matrix as a 100*100 matrix ?
Thank you in advance for your response, and sorry for my english.