Sometimes, Matlab is really good at plotting data for analysis or image processing. The simple figure() function can be used to create a new figure to plot on. Otherwise, it will plot directly on the last existing (or the current figure, which can be accessed via gcf function) figure. Moreover, the existing plotted data would be overwritten if you forgot to turn 'hold on' to preserve the current plots. So it's very common to always call figure() to get a new convas before plotting. However, this leads to another problem that you may get massive number of figures opened after a while using Matlab. I call it as Figure Explosion. To get rid of all open figures, one can simply type 'close all'. However, what if there are some figures you'd like to keep but you just cannot find them manually. How can we close some figures selectively based on there properties, e.g. names maybe? Here it is! The concept is to find all opened figures first. Then, one can cycle through them one by one to check if th figure name (NB. it's different from the figure title) is empty or not. If so, close that specific figure. Looks simply enough, so does the code!
h = findall(groot,'Type','figure'); for i = 1 : length(h) if isempty(h(i).Name) close(h(i)); end end
No comments :
Post a Comment