Search code examples
matlabmat-file

How can I determine the version of a MAT file from MATLAB?


I am wondering if there is a way to determine whether a particular MAT file is v4, v6, v7 or v7.3?

I am looking for a solution that can determine the version using MATLAB code, preferably without having to load the data into memory.


Solution

  • There is some comment at the beginning of mat-files version 6 or following. This code reads it:

    function txt=getMatComment(x)
    fid=fopen(x);
    txt=char(fread(fid,[1,140],'*char'));
    txt=[txt,0];
    txt=txt(1:find(txt==0,1,'first')-1);
    end
    

    It seems the comment is always 116 chars long, but I did not find any reference. This code reads 140 chars and cuts of at the end.

    The part I don't understand: For Version 6 or 7 it says MATLAB 5.0 MAT-file