Printing a TMatrix to a text file?

Hi All,

I construct an actual TMatrixD by simply grabbing information out of a histogram. (I realize that its kinda the same thing)

But when I do something like this:


TFile f("MyRootFile.root");
Plots.cd();
ofstream myout;
myout.open("MyFile.txt");

TMatrixD MyMatrix(8,27);

for (Int_t row=1;row<9;row++)
     {
       for (Int_t column=1;column<28;column++)
            {
              MyMatrix[row-1][column-1]=MyHistogram->GetBinContent(row,column);
            }//end of loop over columns
     }//end of loop over rows

  myout<<MyMatrix.Print()<<endl;

myout.close()

It simply prints the matrix and does not write it into the file? Can anyone help with this?

thanks in advance,

J

Hi,

this topic should be of interest for your case [Writing output of Print to a file however I am not able to reproduce that output…

[code]root [0] gSystem->Load(“libMatrix.so”);
root [1] TMatrixD MyMatrix(8,27);
root [2] for (Int_t row=1; row<9; row++) { for (Int_t column=1;column<28;column++) { MyMatrix[row-1][column-1] = row*100+column; } }
root [3] MyMatrix.Print();>>MyFile.txt

8x27 matrix is as follows

 |       0    |       1    |       2    |       3    |       4    |

0 | 101 102 103 104 105
1 | 201 202 203 204 205

// etc etc

6 | 726 727
7 | 826 827

Error: G__getvariable: expression (tmpfile):1:
Error: Symbol MyFile is not defined in current scope (tmpfile):1:
Error: Failed to evaluate MyFile.txt
*** Interpreter error recovered ***
root [4][/code]