0

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)

Abdulla
  • 5
  • 1

1 Answers1

0

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

Claes Rolen
  • 1,446
  • 1
  • 9
  • 21
  • 1
    According to the Armadillo docs, [.set_size()](http://arma.sourceforge.net/docs.html#set_size) does not guarantee to preserve data. Using [.reshape()](http://arma.sourceforge.net/docs.html#reshape_member) would be more appropriate. – mtall Aug 24 '21 at 00:22
  • Yes, you are right, missed that ... will edit – Claes Rolen Aug 24 '21 at 01:42