MATLAB Answers

0

Recreating a figure from its handle after it has been closed

Asked by Giuseppe Naselli on 31 Aug 2018
Latest activity Answered by Dennis
on 31 Aug 2018
Hi All,
I have a function that creates a figure as below
mainfig = myfunction(x,y)
mainfig = figure('NumberTitle', 'off', 'Name', 'MyFigName');
h.tabgroup = uitabgroup(mainfig);
h.tab = uitab(h.tabgroup, 'Title', 'MyTabName');
h.panel = uipanel('Parent',h.tab);
ax = subplot(2,5,[1 6],'Parent',h.panel);
plot(x,y,'Parent',ax);
end
Now suppose the user calls the function, looks at the figure and then closes it (clicking on the " x " of the figure, top right corner)
I am then left (in the workspace) with the figure handle (mainfig)
Is it possible to re-open/re-create the figure as it was when generated? If yes, could you show an example?
If not, is there any other data I need to add in the output of myfunction in order to achieve that?
Thanks in advance
G

  0 Comments

Sign in to comment.

Products


Release

R2015b

2 Answers

Kelly Kearney 님의 답변 31 Aug 2018

No, the figure handle itself does not contain that information. The graphics objects handles loose their link to the relevant data when the objects are deleted. You would have to save the figure itself (before it was deleted), via savefig... this saves the relevant data needed to recreate the file. Alternatively, you could save the input data used to create the figure (in your example, the x and y variables) and recall the plotting function.

  0 Comments

Sign in to comment.


Answer by Dennis
on 31 Aug 2018

You can change the CloseRequestFcn of your figure to turn your figure invisible rather than closing it. As long as you keep your handle around you can turn it visible again anytime you feel like it.
f=figure;
a=axes;
imshow('autumn.tif','Parent',a)
f.CloseRequestFcn=@savemyfigure;
function savemyfigure(hObj,~)
hObj.Visible='off'
end
Just one thing: this kinda prevents the figure from getting closed...you might want to consider another function to actually close it.

  0 Comments

Sign in to comment.