MATLAB Answers

David T_
2

retrieve mat-file version

David T_
さんによって質問されました 2012 年 8 月 30 日
最新アクティビティ Walter Roberson
さんによって コメントされました 2017 年 8 月 23 日
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 件のコメント

サインイン to comment.

2 件の回答

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 件のコメント

Tom
2012 年 8 月 30 日
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
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
2017 年 8 月 23 日
You can also use fileread() to pull in the entire file, and then examine the first few characters of it.

サインイン to comment.


Tom
回答者: Tom
2012 年 8 月 30 日

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

  0 件のコメント

サインイン to comment.



Translated by