Extract MATLAB legend string from existing plot
<p>I've been trying to get some of the data back out of a plot that's been previously created, but I've been struggling with the legend.  I'm using MATLAB 2014b.</p>

<p>If I previously set my plot up using: </p>

<pre><code>h.fig   = figure();
h.ax    = axes(); hold all;
h.line1 = plot(0:0.01:2*pi(), sin(0:0.01:2*pi()));
h.line2 = plot(0:0.01:2*pi(), cos(0:0.01:2*pi()));
h.xlab  = xlabel('X');
h.ylab  = ylabel('Y');
h.leg   = legend('sin(x)', 'cos(x)');
</code></pre>

<p>Then without having <code>h</code> available I can still retrieve the x and y axis labels as strings:</p>

<pre><code>xlab = get(get(gca, 'xlabel'), 'string');
ylab = get(get(gca, 'ylabel'), 'string');
</code></pre>

<p>However, I don't seem to be able to extract the text from a legend in a similar way.  I notice that:</p>

<pre><code>fig_children = get(gcf, 'children');
</code></pre>

<p>Shows me both the axes and legend as the children of the figure, but I don't seem to be able to access them in the same way I might with the axes:</p>

<pre><code>ax = get(gca);
</code></pre>

<p>I'm probably mis-understanding something obvious about the way that it works, but I can't find a way to get the string out of a legend that's been previously made?</p>