Avoid saving multiple figures when trying to save a figure prompted by a GUI as .fig?
Show older comments
I have a complex GUI that is used to generate multiple plots and figures. Let's call the main GUI figure handles.figureMain and the figure generated by a callback in the main GUI, handles.figurePlot.
In figurePlot, selecting File>Save As... *.fig creates a .fig file that includes both figures: figureMain and figurePlot.
How can I make sure only figurePlot is saved in the .fig file?
Things I have tried that haven't worked:
- Turning off handle visibility to figureMain
handles.figureMain.HandleVisibility = 'Off'
- Turning off graphical visibility to figureMain before saving
handles.figureMain.Visible = 'Off'
- Modifying the File>Save As... menu item in figurePlot to a modified callback function that invokes savefig instead of saveas .
hMenuFile = findall(handles.figurePlot,'type','uimenu','tag','figMenuFile');
hSaveFigure = findall(handles.figurePlot,'type','uimenu','tag','figMenuFileSaveAs');
set(hMenuFile,'Callback','filemenufcn_custom FilePost')
set(hSaveFigure,'Callback','filemenufcn_custom(gcf,''FileSaveAs'')')
(I have also tried gcbo instead of gcf .) Then in filemenufcn_custom > localSaveExportHelper :
if strcmp(types{typevalue,4},'fig') && ~fromExport
savefig(hfig, filename, 'compact')
% saveas(hfig,filename); % original/replaced code
else
...
- Setting the InSaveFig property of figureMain to 'Off'
set(handles.figureMain,'InSaveFig','off')
- I have also checked children and parents, and tracked down the figure handle all the way until it is written using FF.write() in savefig and I cannot find any reason why handles.figureMain should be included in saving handles.figurePlot as a .fig.
The only thing that works (partially) is actually closing figureMain before saving figurePlot but this isn't feasible for my purposes.
Saving the additional figure is quite costly in terms of time and memory so a solution would be appreciated.
Thanks.
6 Comments
Walter Roberson
on 23 Oct 2018
Is it really necessary to support File->save as, when you could put in your own buttons with whatever callback you need?
Is it possible that that FigurePlot has attached to one of its graphic objects a reference to some part of FigureMain?
Gil Zimmerman
on 23 Oct 2018
Walter Roberson
on 23 Oct 2018
Can you attach the fig ? Zip them if you need to.
I will not be able to analyze fig until afternoon my time, but I do have some tools to help me dig.
Christoph Neumann
on 15 Jun 2021
puh, nealy three years ago and no solution? I have the same problem with R2019b.
I could provide the saved *.fig but not per email, since it's size is 200MB.
Christoph Neumann
on 15 Jun 2021
This malfunction appears (in my application) only together with "copyobj", where an axes from the GUI main window is copied to the separate figure. In this case, "saveas" or "savefig", addressing the separate figure, is saving both the GUI main window and the separate figure.
Gil Zimmerman
on 15 Jun 2021
Accepted Answer
More Answers (0)
Categories
Find more on Printing and Saving in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!