Losing decimals when loading a csv into a fmat in C++ using Armadillo

72 Views Asked by At

My code is simple:

arma::fmat fromMatlab;
fromMatlab.load(relPath + "/matrix.csv", arma::auto_detect);

My csv contains numbers like:

0   0   2   4.8989795   -6.9282032  -4.8989795  -16.970563  -16.970563  28.284271

But my c++ code returns numbers without decimals like:

0            0   2.0000e+00   4.0000e+00  -6.0000e+00  -4.0000e+00  -1.6000e+01  -1.6000e+01   2.8000e+01

I tried to load data from a mat too, and defining my fromMatlab variable as a mat, fmat, Mat, Mat, and the error is always the same.

What is happening? I'm working with armadillo 12.6 and this didn't happen with 7.95 version...

1

There are 1 best solutions below

1
Valdez On

Without at the armadillo source code it will be really hard to deduce what may be leading to your current error, but if I were to guess (and this is only a guess) is that there is some conversion from a float/double to an integer during your load, as I can see that anything after the decimal point is being cut off (maybe the load function is expecting to read in ints and your are printing out floats). It could also be a problem during printing, my suggestion is that you put a break point before the print statement and see whats actually written in memory (Visual Studio allows you to do this through the debugger). Also it would be worth visiting their documentation to determine if the use of auto_detect is appropriate and if maybe this option might be leading to the data in the file being read as integers. Maybe you could try using other load options such as raw_ascii, which may yield different results.