c++matlabarmadillolapackopenblas

How to import matrix into armadillo using binary files?


I am trying to import a matrix generated in MATLAB into armadillo. For example, I have a matrix "A" which is 100x1 double. I used information from a previous question on stackoverflow to generate a binary file using MATLAB:

% Generate LocalX.bin
name = 'LocalX.bin';
[F,err] = fopen(name,'w');
if F<0,error(err);end
fwrite(F,LocalX, 'int32');
fclose(F);

and I imported it into armadillo using:

arma::Mat<int> LocalX;
std::string localx = "LocalX.bin";
LocalX.load(localx, arma::arma_binary);

The issue is, I have lost the matrix dimensions and I cannot perform any matrix manipulation on it using aramdillo.

How do I import the data into armadillo while maintaing the matrix dimensions?

Thank you.

(First time asking a question on stackoverflow)


Solution

  • If you know the dimensions (ROWS,COLS) beforehand you can add LocalX.reshape(ROWS,COLS) after you have loaded the matrix.