I am creating a figure with multiple subplots and saving it to a file. like this:
fig = figure;
ax1 = subplot(2, 1, 1);
ax2 = subplot(2, 1, 2);
ylabel(ax1, 'First');
ylabel(ax2, 'Second');
savefig('myfigure.fig')
Later, I want to copy one of the subplots to a new figure without re-running the code that creates the figure. My current approach is to load the saved figure, locate the axes I want to copy by its YLabel, and then copying it to a new figure:
newfig = figure;
oldfig = openfig('myfigure.fig');
ylabel_obj = findobj(oldfig, 'String', 'First'); % This is not givng me what I expect
old_axes_obj = ylabel_obj.Parent;
new_axes_obj = copyobj(old_axes_obj, newfig);
The problem is that findobj above is not finding the YLabel. It just returns a 0x0 empty GraphicsPlaceholder array. Why isn't findobj finding my YLabel? Is there a better way to find the axes I want?