MATLAB Answers

2

retrieve mat-file version

Asked by David T_ on 30 Aug 2012
Latest activity Commented on by Walter Roberson
on 23 Aug 2017
Hello community,
I want to use the MATFILE command to access specific data in .mat-files. Is there a function which returns true if the .mat-file format is 'v7.3' and false otherwise?
I know you can check this in the command window using
type myfile.mat
However you cannot use TYPE within a function, which is what I want to do.
Thanks in advance
David

  0 Comments

Sign in to comment.

2 Answers

Answer by Daniel Shub
on 30 Aug 2012
 Accepted Answer

You can use evalc to capture the output of type
function tf = getmatv(fname)
x = evalc(['type(''', fname, ''')']);
tf = strcmp(x(2:20), 'MATLAB 7.3 MAT-file');
end

  4 Comments

Show 1 older comment
Tom
on 30 Aug 2012
I'd have thought there'd be an easier way to determine it? You can also do it through fscanf
fname='myfile.mat';
fclose('all')
[fid,e]=fopen(fname);
S=fscanf(fid,'%c');
fclose(fid)
S(1:regexp(S,',','once')-1)
but it still seems overly complicated.
Daniel Shub
on 30 Aug 2012
I was really answering the "you cannot use TYPE within a function" part of the question. I am not sure you want to use TYPE, but I wanted to provide a way to do it.
Walter Roberson
on 23 Aug 2017
You can also use fileread() to pull in the entire file, and then examine the first few characters of it.

Sign in to comment.


Tom
Answer by Tom
on 30 Aug 2012

type(FileName)
should work fine, where FileName is a string containing the file name, e.g.
FileName='myfile.mat'

  0 Comments

Sign in to comment.