Edit header of MAT-File

조회 수: 29 (최근 30일)
Christian Tieber
Christian Tieber 2019년 7월 4일
편집: Guillaume 2019년 7월 5일
How can i read and edit the header of a MAT-File?
I have a signal that i am working with in matlab. Obviousliy the signal has a start- and endpoint.
After saving the signal as MAT-File i would like to be able to get the information of start- and endpoint without opening the file.
My idea would be to write this information in to the header.
Any suggestions?
thanks!
  댓글 수: 4
Christian Tieber
Christian Tieber 2019년 7월 4일
편집: Guillaume 2019년 7월 4일
"Furthermore, the only thing it is designed to store is variables, not any kind of metada."
Thanks for your help. but i dont think thats correct.
Walter Roberson
Walter Roberson 2019년 7월 4일
You are proposing to change the first 124 bytes of the file to store the data you are interested in? That is technically possible, but not recommended. But if you did do that, it would not be possible to retrieve the data without opening the file -- though it would be possislbe to retrieve it without loading the file. But if the task is to retrieve data without loading the file, consider encoding the information in the names of variables and then using whos -file

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

답변 (1개)

Guillaume
Guillaume 2019년 7월 5일
Ok, you could theoretically store some limited metadata in the header of a version 5 mat file. It's been a while now that matlab has switched the default over to the newer 7.x mat file format which is completely different, based on HDF and completely undocumented. This format probably also has a way to embed some metadata.
My point still stand, these files are intended to store variables and variables only. Matlab does not give you any way to read or write metadata in a m file. With version 5, you'd either have to use an external program or edit the binary stream within matlab, in each case being careful not to corrupt the file. with version 7, you could manipulate the file with the HDF functions, again you'd have to be careful not to corrupt anything.
And then if you'd managed to embed the metadata, what? No other program knows how to get at it. Your file explorer certainly wouldn't know about it. As others have said, you could embed a limited amount of metadata in the file name. Better yet, have a spreadsheet or a database linking the file names to the metadata, that way you have no restriction on the amount of metadata you can store and it's a lot easier to search through.
  댓글 수: 4
Bjorn Gustavsson
Bjorn Gustavsson 2019년 7월 5일
The problem I seem to run into with setups using metadata in database/lookup-files is that they get out of sync too easily, or that the work keeping them up-to-date and accurate becomes "sensitive" (Is the database up-to-date? Was this data included in last update? and so on). I prefer to have the metadata closely tied to the data. When I worked with database configurations for metadata, I prefered if the famous someoneelse keep the database syncronized.
Since one can save multiple variable to a .mat-file why muck about squeezing in header-data in some unspecified space in files with slightly incomplete documentation, in that case why not simply save all meta-data in a variable named metadata, or header. Then the meta-data-reading function would be no more than:
function header = metadatareader(filename)
load(filename,'header')
end
Guillaume
Guillaume 2019년 7월 5일
편집: Guillaume 2019년 7월 5일
The problem I seem to run into with setups using metadata in database/lookup-files is that they get out of sync too easily
Why not store the metadata, and the mat file in the database, then? I'm assuming a proper database here.
Personally, what I do when processing data with matlab is not only store results but also the required inputs and the code version that was used to produce these results together in the mat file. There is then no question of what input was used? or was this produced by the version of the code that had a bug? when looking at the results some times later. Said code will also refuse to run if it's not a clean checkout from the version control system.
edit: which is more or less what you recommend and I agree probably the best way to proceed

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

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by