brian
brian

Reputation: 157

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.

Upvotes: 0

Views: 280

Answers (2)

Stefan Gerlach
Stefan Gerlach

Reputation: 1

To access the data of a variable you have to use Mat_VarRead() instead of Mat_VarReadInfo(). Otherwise matvar->data is NULL.

Upvotes: 0

Nils
Nils

Reputation: 2695

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.

Upvotes: 1

Related Questions