Recreating a figure from its handle after it has been closed
33 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (3 件)
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 件のコメント
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 件のコメント
Diêgo Carneiro
2022 年 2 月 23 日
編集済み: Diêgo Carneiro
2022 年 2 月 23 日
You can save the figure parameters in a struct using get(mainfig). For example:
fighandle = get(mainfig);
However, you can't recreate the figure just using fighandle, but you will have access to the parameters. If you want to create a new figure based on the previous one, you could do as follows:
fighandle = get(mainfig);
fig2 = figure;
set(fig2,'Name',fighandle.Name,'Units',fighandle.Units)
Ps: I am working in a function to transform the struct in a figure object
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Subplots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!