MATLAB Answers

0

Recreating a figure from its handle after it has been closed

Giuseppe Naselli さんによって質問されました 2018 年 8 月 31 日
最新アクティビティ Dennis
さんによって 回答されました 2018 年 8 月 31 日
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 件のコメント

サインイン to comment.

製品


リリース

R2015b

2 件の回答

Kelly Kearney
回答者: Kelly Kearney
2018 年 8 月 31 日

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 件のコメント

サインイン to comment.


Dennis
回答者: Dennis
2018 年 8 月 31 日

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 件のコメント

サインイン to comment.



Translated by