Search code examples
c++matio

Reading in Matlab .mat file: variable's rank and dims correct, but data is NULL


I'm trying to read in a .mat file from Matlab using matio and the variable comes in with the the correct rank and dims, but the data is null:

mat_t    *matfp;
matvar_t *matvar;
matfp = Mat_Open("the_file.mat",MAT_ACC_RDONLY);
matvar = Mat_VarReadInfo(matfp,"my_var");

assert(matvar->rank==2);
assert(nrows==matvar->dims[0] && ncols==matvar->dims[1]);

but

matvar->data==NULL

I'm assuming something is going wrong reading in the .mat file, but I'm not sure how to diagnose it.


Solution

  • You should check the MATLAB file version.

    Maybe the file is written in MATLAB version 7.3 or with compression.

    If you build your lib (matio) without zlib you can not read compressed data. If you build without zlib and HDF5 you can not read file version 7.3 files.