This forum has been archived. All content is frozen. Please use KDE Discuss instead.

easy question: print matrix to a file

Tags: None
(comma "," separated)
esum
Registered Member
Posts
2
Karma
0
I want to print the values of my matrix to a file so that I can use the data in another program.

This was my first attempt and it doesn't work. I'm sure it's because I'm not using fprintf correctly. Please help!

Code: Select all
#include <stdio.h>
#include <Eigen/Dense>

using namespace Eigen;
int main ()
{
   FILE * pFile;
   int n;
   char name [100];

   pFile = fopen ("myfile.txt","w");
   MatrixXf myMat= MatrixXf::Random(5,5);
   fprintf(pFile, "%4.2f", myMat);
   fclose (pFile);
   return 0;
}
ACromulentTag
Registered Member
Posts
5
Karma
0
I don't think you can pass a Matrix object to fprintf. Try using fstream instead:

Code: Select all
#include <fstream>

fstream f;
f.open("myfile.txt",ios::out);
f<<myMat<<endl;
f.close();


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]