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일

1 개 추천

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

David T_
David T_ 2012년 8월 30일
Yep... forgot about EVALC
Thanks
Tom
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
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일

2 개 추천

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

카테고리

도움말 센터File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

제품

질문:

2012년 8월 30일

댓글:

2017년 8월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by