Search code examples
matlabmatio

Using Mat_CreateVer for MATLAB versions higher than 7.3


I have a C++ application for Windows platform. This application creates MAT-files. Presently we support only versions 4, 5 and 7.3 of MATLAB. We want to add support for higher MATLAB versions.

In .h (downloaded from https://sourceforge.net/projects/matio/), in the enum mat_ft, there is support for only three MATLAB versions: 4, 5 and 7.3.

enum mat_ft {
    MAT_FT_MAT73  = 0x0200,   /**< @brief Matlab version 7.3 file             */
    MAT_FT_MAT5   = 0x0100,   /**< @brief Matlab version 5 file               */
    MAT_FT_MAT4   = 0x0010,   /**< @brief Matlab version 4 file               */
    MAT_FT_UNDEFINED =   0    /**< @brief Undefined version                   */

};

To create a MAT-file while calling Mat_CreateVer we pass the above enum

pMat = Mat_CreateVer(matFileName.append(".mat").toLocal8Bit().data(), NULL, MAT_FT_MAT73);

This is OK for MATLAB versions up to 7.3. I have to call Mat_CreateVer() for MATLAB R2016b and other higher version up to R2023b. What enum value I should pass?


Solution

  • The MAT file versions correspond to the version number of MATLAB when they were introduced. MAT file version 7.3 is good for MATLAB v7.3 (release R2006b) and later. The file format has not been changed since (as of R2023b), so that is the still latest. See this doc page for a list of MAT file versions.

    Also note there's a difference between the MATLAB version and the release, returned by matlabRelease.