This example shows how to extract data from a MATLAB figure.
If the figure is stored in a file, such as 'example.fig', then open the figure file using 'openfig'. Assign the Figure object to the variable 'fig'.
fig = openfig('example.fig');
If the figure is already open, then use 'gcf' to access the Figure object and assign it to the variable 'fig'.
There are several ways to access the data for the plotted graphics objects. You can use the Children property or you can use 'findobj'.
Use Children Property
Access the plotted graphics objects through the Children properties. The Axes objects are children of the figure. The plotted graphics objects are typically children of the Axes object.
axObjs = fig.Children
dataObjs = axObjs.Children
The 'dataObjs' array that appears in the Command Window indicates the types of graphics objects in the axes. Different graphics objects store data differently. For example, Line objects store the data in the 'XData', 'YData', and 'ZData' properties. If the first element in 'dataObjs' is a Line object, then access its data using this code.
x = dataObjs(1).XData
y = dataObjs(1).YData
z = dataObjs(1).ZData
If the figure contains other types of graphics objects, then use the appropriate properties to access the data. For a list of graphics objects and their properties, see:
Use findobj Function
Alternatively, you can find all the graphics objects in a figure with a certain data property. For example, find all graphics objects that have a 'YData' property. Then access the 'YData' values for the first object.
dataObjs = findobj(fig,'-property','YData')
y1 = dataObjs(1).YData