MATLAB Answers

David T_

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

  0 件のコメント

サインイン to comment.

2 件の回答

Daniel Shub
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');

  4 件のコメント

on 30 Aug 2012
I'd have thought there'd be an easier way to determine it? You can also do it through fscanf
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.

サインイン to comment.

Answer by Tom
on 30 Aug 2012

should work fine, where FileName is a string containing the file name, e.g.

  0 件のコメント

サインイン to comment.

Translated by