2019년 10월 29일 화요일

matlab file load, save

1. what is mat file
MAT-files are binary MATLAB® files that store workspace variables.
matlab 에서 사용하는 binary 파일이다. 세부 형식은 matlab 고유의 방식이지 않을까

Starting with MAT-file Version 4, there are several subsequent versions of MAT-files that support an increasing set of features. MATLAB releases R2006b and later all support all MAT-file versions.
지금까자 여러 버전의 mat 파일이 존재하며 R2006b 부터는 모든 mat 파일이 지원된다고 하니 이후에는 업데이트 된 것이 없다고 봐야 하는 것인가.


2. load function
load('filename') 일 때는 filename 에 확장자가 명시되어 있으며 확장자를 따른다. mat 형식이나 ascii 형식이 있을 수 있다. 그래서 mat 이라고 적혀있지 않으면 ascii 형식으로 load 한다.
그래서 load('filename', '-mat') 으로 하면 확장자에 구애하지 않고 mat 파일을 load 한다.

3. save function
save('filename', '-struct', structName) 일 때 structName 구조체의 값들을 filename 에 개별 변수로 저장한다.
이 때 이렇게 저장한 filename 을 tmp_name = load('filename', 'mat') 으로 load 하면 tmp_name 이 structName 의 모든 변수를 가진 구조체가 된다.