How can a Eigen matrix be written to file in CSV format? -


suppose have double eigen matrix , want write csv file. find way of writing file in raw format need commas between entries. here code foudn simple writing.

void writetocsvfile(string name, matrixxd matrix) {   ofstream file(name.c_str());   if (file.is_open())   {     file << matrix << '\n';     //file << "m" << '\n' <<  colm(matrix) << '\n';   } } 

using format bit more concise:

// define format want, need 1 instance of this... const static ioformat csvformat(streamprecision, dontaligncols, ", ", "\n"); 

...

void writetocsvfile(string name, matrixxd matrix) {     ofstream file(name.c_str());     file << matrix.format(csvformat);  }