MATLAB Answers

Avoid saving multiple figures when trying to save a figure prompted by a GUI as .fig?

3 views (last 30 days)
Gil Zimmerman
Gil Zimmerman on 23 Oct 2018
Commented: Walter Roberson on 23 Oct 2018
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.
  3 Comments
Walter Roberson
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.

Sign in to comment.

Answers (0)

Products


Release

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!