MATLAB: Exporting plot as .png from GUI with multiple axes

export imageexport plotexport png

Hi,
I'm writing a GUI which continuously updates a set of plots within a figure (there are three axes showing, with their separate plots, all within that one figure). What I want to do is to export one of those plots as a png file. My problem is that I can't seem to do that correctly. I've tried a couple of things:
Using imwrite:
axes(myAxes);
dataPlot = imagesc(data);
dataFrame = getframe(myAxes);
[im,imMap] = frame2im(dataFrame);
imwrite(im,'fileNameHere');
The problem is that if I'm running the GUI in the background, it saves images of whatever's in the foreground, and not the actual plot that I want.
Using print:
*Plotting like above*
print('-dpng','fileNameHere');
But (I think, at least) that works only for entire figures, so it stores the entire GUI frame, which is more than what I need (and it looks more confusing too as an image).
One option, of course, is to create a temporary figure, plot it there and use print, but that slows the processing down a little, and looks really un-cool and un-swift, so I'd prefer to avoid that method.
I've noticed export_fig on File Exchange (which certainly looks like it could do the trick), but I was hoping there would be a simple built-in way of doing this. Is there one? (Pardon my noob-iness, I'm fairly new to Matlab)
Thanks for any help!

Best Answer

You are right: getframe requires to the figure to be on top of others.
You can create 1 figure outside the visible screen area and use print() after duplicating the axes by copyobj. Then do not delete the figure, but only remove the contained axes as obtained as output of copyobj. Then you save the time consuming creation of the figures and can export the pictures without disturbing the current work.
I'm currently working on a method to capture the figures contents of covered windows under Windows, but this is published already: http://www.mathworks.com/matlabcentral/fileexchange/42841-windows-screenshots