Why does MATLAB open a plot window when I load a .mat file that contains a figure inside an struct?
The problem that I am facing is that I have the output of an optimization algorithm as a collection of .mat files. Each .mat file contains the state of each generation of the algorithm in a form of a single struct. The state structure has (among other variables) a field of type matlab.ui.Figure. Now, whenever I try to load any of these files with the load command, a plot window opens automatically.
Is there any way to stop MATLAB from from opening this plot window?
I am using MATLAB 2015rb.

The reason that it is displaying a figure is because if you look closely at your
statestructure, there is afigureobject stored in there. When you load this graphics object (or any object, really) from a file, MATLAB will reconstruct the object. The defined behavior for loading a figure (it'sloadobjmethod) is to open the figure.This is a recent issue because older versions of MATLAB stored graphics handles as simply a number and when loading a graphics handle from file, MATLAB had no way of knowing that it was supposed to be a figure so it would just parse it as a number and move on without displaying a new figure window.
Unfortunately since your
figurehandle is nested within astructthere is no easy way to not load it. Probably the easiest thing to do would be to just delete the figure object right after loading the file (since you have the handle already).And if you really don't like the figure poping up even for a second, you can set the default figure
Visibleproperty to'off'prior to loading and then reset it afterwards.Another potential solution (which would not require you to know where the
figurehandles are in your struct) is to overwrite theDefaultFigureCreateFcnto simply delete any figure that is created.In the future, to avoid this behavior, consider not saving any graphics handles within your .mat files. They are very large objects and MATLAB actually will issue a warning when saving one to a file as it is not recommended.