MATLAB Answers

C++ .MAT file format

17 views (last 30 days)
Nycholas Maia
Nycholas Maia on 2 Feb 2020
Commented: Nycholas Maia on 4 Feb 2020
I have a C++ application that generates a lot of numerical matrices and vectors using C++ numerical libraries as Eigen and Blaze (and std::vector too)
I would like to store these results in a file that could be opened in MATLAB.
I saw that MATLAB have a C/C++ API that enable developers store numbers/strings in the *.mat file format.
But in this MATLAB API my C++ matrices and vectors should be mxArray pointer.
How can I use this MATLAB API to store my Eigen and Blaze matrices?

  2 Comments

James Tursa
James Tursa on 3 Feb 2020
Can you simply write the matrices out to a binary file and then use fread to get them into MATLAB?
Nycholas Maia
Nycholas Maia on 4 Feb 2020
Hi @James Tursa,
Yes, I can do that, but my application will generate a lot os matrices and vectors as results.
I would like to retrive each one by a "name" or "id"...
Like "rotation_matrix", "time_vector"...etc...
And another thing:
I would like to get a specific matrix in this file without need to load all file data.
The HDF5 file format can do that and MATLAB have support to it, but I would like to know if there is a good and stable C++ API to help me.
Or if there is another file format that I can obtain these 2 features:
  • Get matrix by name or path
  • No need to load all file data to get some matrix

Sign in to comment.

Answers (0)

Sign in to answer this question.

Products


Release

R2019b