Edit header of MAT-File
18 次查看(过去 30 天)
显示 更早的评论
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 个评论
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
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
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
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 Center 和 File Exchange 中查找有关 Large Files and Big Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!