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)

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

2 Comments

According to the Armadillo docs, .set_size() does not guarantee to preserve data. Using .reshape() would be more appropriate.
Yes, you are right, missed that ... will edit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.