Is there a way to include a header comment for a mat file?

2 visualizaciones (últimos 30 días)
David Rayner
David Rayner el 18 de Sept. de 2020
Respondida: Walter Roberson el 18 de Sept. de 2020
Scientists often have a lot of scripts which run particular analyses, and running doc on a directory is a great way to get a summary of what all the scripts/functions do:
>> doc('Max_1h_prcp')
Contents of Max_1h_prcp:
RCM_fit_mm - Fit Pareto and Exp by month
ks_mean_groups - ks-means using 95th percentile
model_changes - plot maps changes
msb_fitExponentialTail - fit an exponential using N years data.
msb_fitLognormalTail - fit a Lognormal using N years data.
...
RCM.mat - RCM is a MAT-File.
RCM_fit_mm.mat - RCM_fit_mm is a MAT-File.
RCM_fits.mat - RCM_fits is a MAT-File.
But for those mat files, well the summary is not so useful.
Is there any way to add a comment to a mat file, so it shows up in doc?
If not, would this be a function anyone else would like?

Respuestas (1)

Walter Roberson
Walter Roberson el 18 de Sept. de 2020
Unfortunately v4 and v5 and v7 mat files were not defined to allow for comments. The exception is that the first 128 bytes of v5 and v7 files is text and that everything after naming the version is ignored, so about 110 bytes are available.
In theory Mathworks could extend the v5 and v7 header to include a comment marked as such, but doing so would cause backwards compatibility problems.
v7.3 mat files are hdf5 files, and that standard has no provision for file comments. The standard does have an Object Comment that can be applied to each data object, but there is not one for the file level as far as I can see.
I suspect that the easiest approach would be to designate a particular variable name to store in the file as a file description, and to write a small wrapper that checks the file for that variable and pulls it out and displays it if present. You would need to decide between char() vs string() vs cell array of character vectors.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by