Q:

How to add metadata to MATLAB figure?

Summarizing large amounts of data from different measurements I create figures in MATLAB. I would like to add metadata to these figures.
The metadata could be things like code version and information regarding the measurement. One option is plainly adding this information as text in the figure, but this is distracting and the information can be a large amount of text. Another is adding a README file to the folder that contain the figures, however this file can get lost.
Is there a way of attaching this metadata directly to a MATLAB figure? I expect the data to be accessible when opening the figure in MATLAB, without it distracting from the figure content.

A:

You can easily do it by using the UserData property of the figure in which you can store all the "metadata".
In the following example, a plot is added in a Figure and the data used for the plot are saved in the Figure property.
You can improve the example by adding, foir example, a pushbutton to be used to retreive the metadata.
If your figure is actualy a GUI you can add, for example, a text field in which show to metadata.
% Create a Figure
my_fig=figure
% Define some data
t=0:.01:360;
y=sind(t);
% Plot data
plot(t,y);
grid minor

% Create a struct in which to store the data
metadata_struct.version=1.3
metadata_struct.t_values=t
metadata_struct.y_values=y

% Assign the struct with the metadata to the "UserData" property
my_fig.UserData=metadata_struct
% Save the Figure
savefig(gcf,'my_fig_with_metadata.fig')

% Open the Figure
fig=openfig('my_fig_with_metadata.fig')
% Get the Metadata
fig_metadata=fig.UserData
% Use use the MEtadata
fig_metadata.version

