MATLAB: How to obtain data in a matrix from fig.file

cdatamappingfigurematrixsurf

Hi,
A colleague gave a fig. file which is a 2D matrix with a scale color from 0 to 255. He plotted the data, saved them in a fig file a sent to me. I would like to suf the data and for that I need to extract the data. I am using for that this code:
openfig('figure.fig')
h = gcf;
axesObjs = h.Children;
dataObjs = axesObjs.Children;
data = dataObjs.CDataMapping;
But I got the error
No appropriate method, property, or field 'CDataMapping' for class 'matlab.graphics.GraphicsPlaceholder'.
What is wrong?

Best Answer

The ‘Children’ propertiy disappeared with the introduction of ‘HG2’ (handle graphics version 2) in R2014b.
You most likely need to use the findobj (link) function.
Example —
figure
surf(rand(10))
h = gca;
srf = findobj(h,'Type','Surface');
X = srf.XData;
Y = srf.YData;
Z = srf.ZData;
That should return all the data you want. To see all the fields in the ‘srf’ structure, use:
sp = get(srf)
to display them.
Related Question