MATLAB: Save a single subplot from a .mat file that contains 2×1 subplots

gcagcfsubplots

I have a saved .mat figure with two subplots as a 2×1. I have no access to the code. What is the fastest way to get the 1×1 subplot and plot it on a new figure by it self.
My temp solution…
I ended up selecting the "pointer/mouse" icon and just deleted the second subplot. Resized the desired plot and then saved it.
Can someone provide a coded solution?

Best Answer

There's nothing wrong with your solution of deleting the unneccessary subplot and resizing the desired one. If you need to do this with many subplots, you can write a short function or script like this
% get handles to axes of current figure
axh = findobj(gcf,'Type','axes');
% Delete the 2nd axes
delete(axh(2))
% expand the size of 1st axes
axh(1).Units = 'Normalize'; % I prefer working in normal units
axh(1).Position = [.1,.1,.8,.8];
An alternative would be to merely copy the content of the desired subplot onto a new axis within a new figure using copyobj()
% Create new figure and new axes
figure();
newax = cla();
% Copy the content (children) of 1st axes into the new axes.
copyobj(axh(1).Children,newax)