how to get mat file version, type(matfile) doesn't work

조회 수: 20 (최근 30일)
Kangle Li
Kangle Li 2020년 4월 15일
댓글: Stephen23 2020년 4월 16일
Hi, I tried "type(matfilename)" to get the mat file version, but this command will type out the contents of the mat file, not the version. So how to get the version of a mat file? Thanks in advance!
  댓글 수: 1
Stephen23
Stephen23 2020년 4월 16일
Did this behavior change? It worked for me on R2012b:
>> X = 1:3;
>> save('test.mat','X')
>> type('test.mat')
MATLAB 5.0 MAT-file, Platform: PCWIN, Created on: Thu Apr 16 11:08:37 2020

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2020년 4월 15일
fread() the first 16 bytes of the file.
'MATLAB 5.0 MAT-file' -> MATLAB 5.0 or 7.0 .mat file, saved with -v6 flag or with -v7 or (typically) with no -v flag
'MATLAB 7.3 MAT-file' -> MATLAB 7.3 .mat
no 'MATLAB' string at beginning but you know it is a .mat file -> .mat saved with -v4 flag
If you need to detect whether a file was stored with -v6 versus -v7 then there would be more work involved. The header does not differentiate between the two, but since -v6 does not support compression, it would be possible to look for clues such as the existence of compressed variables

추가 답변 (0개)

카테고리

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