retrieve mat-file version

120 次查看(过去 30 天)
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

采纳的回答

Daniel Shub
Daniel Shub 2012-8-30
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 个评论
Daniel Shub
Daniel Shub 2012-8-30
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
Walter Roberson 2017-8-23
You can also use fileread() to pull in the entire file, and then examine the first few characters of it.

请先登录,再进行评论。

更多回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Workspace Variables and MAT-Files 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by