0

I have a matrix A stored in column major order as

1 3 2 4

and I'm using this function to output it in row major order, i.e.

1 2 3 4

which is does correctly. However I'm confused about how it does this, as I thought the loops would work by going i = 0 j =0, i = 0 j = 1, i = 1 j = 0, i = 1 j = 1.

But this would give me

data[0]

data[1]

data[2]

data[3]

my original matrix? Can anyone please explain this as I'm baffled?!

Thanks in advance!

```
void Matrix::WriteToFile(std::string fname) const
{
ofstream myfile;
myfile.open ( (fname+".txt").c_str() );
for (int i = 0; i<mdim_; i++)
{
for (int j = 0; j<ndim_; j++)
{
myfile << data_[i * ndim_ + j] << " ";
}
}
myfile.close();
}
```