MATLAB: Extracting data from Contour plots

dataobjsextracting data from figures

I am trying to extract data from a contour plot. I managed to get all the information about the dataObjs using
open('colormapinhomo.fig');
h = gcf;
axesObjs = get(h, 'Children');
dataObjs = get(axesObjs, 'Children')
dataObjs{2}
Contour with properties:
LineColor: [0 0 0]
LineStyle: 'none'
LineWidth: 0.5000
Fill: 'on'
LevelList: [1×62 double]
XData: [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40]
YData: [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20]
ZData: [20×40 double]
but cant get the data itself. Any help ? And is this the only way to extract data, or can I somehow output a .dat file of the figure with the data whether it was a contour or a histogram or even a simple plot line ?

Best Answer

If you want the contour (x,y) values, you have to ask for them:
figure(1)
[C,h] = contour( ... );
The (2xN) ‘C’ array will have the (x,y) values of the contour lines. The first column in each has the contour value as the first row and the number of (x,y) values defining the contour as the second row. (It requires some coding to extract all of them effectively.) Use the LevelList property to find the values of the contours (these will match the first row and first column of each contour) so you can then use find to locate the beginning of each (x,y) contour matrix.
See the documentation for contour for details. There is a link to ‘Contour Properties’ that lists all of them.